Convert Rows to Columns

Hi Everyone,
Could someone shed some lights on how to convert the records in rows form into column basis.

172.29.59.12
 IBM,8255-E8B
 102691P
 8
 65536 MB
6100-04-11-1140

172.29.59.15
 IBM,8255-E8B
 102698P
 4
 45056 MB
6100-04-11-1140


IP                SYS MODEL         SN           CPU    MEMORY     OSLEVEL
--                -----------         --            ----   --------     ---------
172.29.59.12  IBM,8255-E8B     102691P    4        65536 MB   6100-04-11-1140
172.29.59.15  IBM,8255-E8B     102698P    4        45056 MB   6100-04-11-1140

Thanks.

awk '!$0{print;next}{printf $0"\t"}' infile

and yeah, the headers you can echo it or print them in the BEGIN block of awk .

HTH

--ahamed

Thanks Ahamed. Could you explain a bit on the script you posted ? This is simple but quite powerful

awk '{$1=$1}1' RS="\n\n" file
172.29.59.12 IBM,8255-E8B 102691P 8 65536 MB 6100-04-11-1140
172.29.59.15 IBM,8255-E8B 102698P 4 45056 MB 6100-04-11-1140

Normal record selector RS is a single new line.
I do set it to two new line (as a blank line would give) RS="\n\n"
Then I do tell awk to reconstruct the data using new RS with $1=$1
Last, print everything out 1

There you go...

awk '
        {printf $0"\t"}         #Print each line without a newline separated by tab
        !$0{print;next}         #If there is an empty line, then print it with new line, this is 
                                #what basically separates the records
' infile

--ahamed

That's why its working fine to just change the record separator RS :slight_smile:
Like the example in my post #4

:slight_smile:
Yup... I somehow miss this RS logic always...

--ahamed