Hi there,
With the following script I can look for a specific pattern in the focus position of an array, called 'size' (this array contains a focus position with left and right context)
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=w[i+1]
w=$0
if(w[focus]~pattern){
for(i=1; i<=size; i++)
print i, w, w[i+1]
printf("\n"
}
}
Command line: gawk -f script.awk - v right=3 -v left=2 pattern=eeff filename.txt
PROBLEM: If the pattern occurs in the last n lines of the file (n=right), the array (with this pattern in the focus position) is not printed. What should I write in the END-block in order to fix this problem?
Please help me out here. Many thanks.
Kay
ps: I've created a test-file that looks like this:
aabb
ccdd
eeff
gghh
iijj
kkll
mmnn
oopp
qqrr
sstt
uuvv
eeff
yyzz
With the following script I can look for a specific pattern in the focus position of an array, called 'size' (this array contains a focus position with left and right context)
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=w[i+1]
w=$0
if(w[focus]~pattern){
for(i=1; i<=size; i++)
print i, w, w[i+1]
printf("\n"
}
}
Command line: gawk -f script.awk - v right=3 -v left=2 pattern=eeff filename.txt
PROBLEM: If the pattern occurs in the last n lines of the file (n=right), the array (with this pattern in the focus position) is not printed. What should I write in the END-block in order to fix this problem?
Please help me out here. Many thanks.
Kay
ps: I've created a test-file that looks like this:
aabb
ccdd
eeff
gghh
iijj
kkll
mmnn
oopp
qqrr
sstt
uuvv
eeff
yyzz