Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorry, there was a mistake in the script

Status
Not open for further replies.

kayman

Technical User
Oct 8, 2003
2
GB
Hello,

This should be the correct script:

BEGIN{
if(right==0)
right=left
size=left+right+1
focus=left+1
}
{
print "linenumber= " NR
print "line= " $0
for(i=1; i<size; i++)
w[ i]=w[i+1]
w[ i]=$0

if(w[focus]~pattern){
for(i=1;i<=size;i++)
print i, w[ i], w[i+1]
printf(&quot;\n&quot;)
}
}

Now, given the command line (gawk -f script.awk -v right=3 -v left=2 pattern=eeff filename.txt) what should I write in the END-block so that the program also puts the n last lines (n=right context) in the focus position?

Many thanks,

Kay

ps: the file on which the script is tested looks like this:

aabb
ccdd
eeff
gghh
iijj
kkll
mmnn
oopp
qqrr
sstt
uuvv
eeff
yyzz

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top