The problem is with the footer as in awk you don't know
the number of records in a file before the "END" block.
Therefor, you don't know whether you're processing a footer
or you're still in the "body" of the file.
The easiest way is to calculate the number of records/lines
in a file prior to calling awk/nawk and pass the "begin/end"
pivots to awk.
# awk program to strip first and last 3 lines from a file.
{
if (NR == 4)
hld[0] = $0
else if (NR == 5)
hld[1] = $0
else if (NR == 6)
{
hld[2] = $0
ix = 0
}
else if (NR > 6)
{
print hld[ix]
hld[ix] = $0
ix++
if (ix > 2) ix=0
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.