Transpose multi-line records into a single row

Now that I've parsed out the data that I desire I'm left with variable length multi-line records that are field seperated by new lines (\n) and record seperated by a single empty line ("")

At first I was considering doing something like this to append all of the record rows into a single row:

awk 'BEGIN {FS= "\n";RS=""} {print $1,$2,$3,$4,$5,etc. > "NEWdata.txt" }' data.txt

Then I realized that these are not fixed length records, they're each a different number of rows. Is there an easy way around this?? Thanks!

Try this one:

awk 'END{p(x)}func p(x){if(x){print x}}NF{x=(x)?x FS$0:$0}!NF{p(x);x=y}' file

like a for loop?

awk 'BEGIN {FS= "\n";RS=""} {for(i=1;i<=NF;i++)printf $i " "; printf "\n"}' input

Ahhhh yes an NF loop! That's what I was trying to think of, thanks mirni!

The previous reply with a function IF statement did not return the desired results but looks like a good effort....even if I cannot interpret it at all =)

Let's try a shorter one :wink:

awk 'BEGIN{FS=RS;RS=KS}$1=$1' file