Awk script help

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
}
}

Any Ideas welcome.

thanx

You need to add getline to your for loop.

BEGIN {FS=OFS=" "}
{
tsttxt=substr($4,1,3)
if( tsttxt == "03:" )
{print
for (i = 1; i <= 13; i++) {
    getline
    print
}

}
}

Quick explanation: "print" is only working on the current input line; "getline" switches the context to the next input line.

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
}

You missed the braces { } that I added to your for loop so that both "getline" and "print" are performed for each loop iteration.

I think this works

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.

Thanks for your help.

It only takes one line:

$4 ~ /^03:/ && n=14, 0 == n--