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("\n"
}
}
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
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("\n"
}
}
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