I want to search a file where the 4th field begins with 03: and then print the line and the following 14 lines.
I can find the 4th field using awk but then I just get the same line repeated 14 times.
BEGIN {FS=OFS=" "}
{
tsttxt=substr($4,1,3)
if( tsttxt == "03:" )
{print
for (i = 1; i <= 13; i++)
print
}
}
Thanks tmarikle -
Its close but not quite - I now get the line with 03: in the 4th field and then just the 13th line after it.
I tried moving the {} around but to no good effect. I need the getline and the print $0 to act together ..
BEGIN {FS=OFS=" "}
{
tsttxt=substr($4,1,3)
if( tsttxt == "03:" )
{print $0
for (i = 1; i <= 13; i++)
getline
print $0
}
The script should work as I modified it. "print $0" is the same as "print" in your script's case. The missing element when you tested it was the braces following the "for" loop.