I have large tab-delimitated lists (see input file) and I need to convert it into tab-delimitated tables (see output file). I would like to do it with an awk script. Any ideas?
Input file:
header1 <tab> a <tab> a <tab> a <tab> a . . .
header2 <tab> b <tab> b <tab> b <tab> b . . .
header3 <tab> c <tab> c <tab> c <tab> c . . .
header4 <tab> d <tab> d <tab> d <tab> d . . .
. . .
Output file:
header1 <tab> header2 <tab> header3 <tab> header4 . . .
a <tab> b <tab> c <tab> d . . .
a <tab> b <tab> c <tab> d . . .
a <tab> b <tab> c <tab> d . . .
a <tab> b <tab> c <tab> d . . .
. . .
Lobaria: can you check whether NF and NR are defined in the END part? Just add a print statement. My hunch is that they will be zero in your version of awk.
Do you have nawk, or mawk, or gawk, or XPG4 awk on your system? Then try with one of those instead.
Modding the script so that it remembers the last values of NR and NF before the END section is not a complicated fix, as such.
Well, my speculation would be that it doesn't remember the NF and NR values in END, since strictly speaking they are no longer defined in that context (intuitively speaking, at least).