Use awk's internal line counter, NR, which is the ordinal number of the current record read: #!/bin/ksh awk ' { if(NR == 1) printf("%s %s %s\n", $1, $2, $3) if(NR == 13) print $2 # save last line f1=$1 f2=$2 } END { # print last line printf("%s %s\n", f1, f2) } ' datafile
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |