Help for this page

Select Code to Download


  1. or download this
        perl -ne 'print $prev, $_ if /foobar/; $prev = $_' file
  2. or download this
        perl -ne 'BEGIN{$re=qr/foo/}if(/$re/){print$p if$p!~/$re/;print$_}
    +;$p=$_' file
    
  3. or download this
        grep -B 1 foobar file
  4. or download this
        perl -ne '$i=$.% 2; $a[$i]=$_; print @a[$i+1..$#a,0..$i] if /foo/'
    + file
        perl -ne '$i=$.% 2; $a[$i]=$_; print @a[$i+1..$#a,0..$i] and @a=()
    + if /foo/' file