Greetings,
Here's my sample data
The "\n" represent new lines and aren't literally in the sample.
They're there just to show where the line breaks are.
80688351 10/28/04 07/06/05 .00 94.75 R
S 3 94.75 07/06/05\n
07/06/05
S\n
60162450 02/09/05 07/07/05 .00 5592.48 G
H 1 5592.48 07/07/05\n
07/07/05
H\n
30434369 07/07/04 07/08/05 .00 78.88 E
H 3 78.88 07/08/05\n
07/08/05
H\n
60064052 08/27/03 07/08/05 .00 92.41 G
H 3 92.41 07/08/05\n
02/29/04
H\n
30213466 07/31/03 07/11/05 .00 962.23 E
S 5 962.23 08/09/07\n
07/11/05
1\n
The file is space delimited and every two lines need to be joined
together to form a single line. The output should be tab delimited.
Here's what I came up with and it appears to work with the exception of
an extra tab at the end of every output line. My question is, how can
this script be made better (i.e. more succinct or efficient)?
BEGIN { FS=" "; OFS=" " }
{ if (NR%2 == 1) {
for (a = 1; a <= NF; a++) {
prev[a]=$a }
prevNF=NF
} else {
for (i = 1; i <= prevNF; i++) {
printf "%s\t", prev[i]
#print "Im first line", i
}
for (i = 1; i <= NF; i++) {
printf "%s\t", $i
#print "Im 2nd line", i
}
printf "%s\n", ""
}
}
Thanks.


|