The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 09-11-2007
fazliturk fazliturk is offline
Registered User
 

Join Date: Aug 2007
Posts: 45
is there any line before aaa and after eee in the file ?

if there is not than the code is;

let "currentline=`grep -n string inputfile|awk -F ':' {print $1} '`-1"
sed -n "${currentline}s/.*/&/p" inputfile>outfile

if there is. it is a bit harder .The code is ;

let "currentline=`grep -n string inputfile|awk -F ':' ' {print $1} '`-1"
let "fisrtpart=$currentline-5"
let "secondpart=$currentline+4"
sed -n "1,${firstpart}s/.*/&/p" inputfile>outfile
sed -n "${currentline}s/.*/&/p" inputfile>>outfile
sed -n "$secondpart,\$s/.*/&/p" inputfile>>outfile
Reply With Quote