Convert column values into row

hi,
I have a requirement where in I read the values from a file using awk. The resulting data should be converted into row format from column format.

For ex: My log file login.lst contains the following

SERVER1 DB1
SERVER2 DB2
SERVER3 DB3
SERVER4 DB4

I use awk to grep only the server names as below

SERV=`cat login.lst | awk '{print $1}' `

echo $SERV prints the output ..

SERVER1
SERVER2
SERVER3
SERVER4

I want the output to be formatted as -- SERVER1 SERVER2 SERVER3 SERVER4

I tried to search the forum for any similar posts, but I couldnt find any clear definition or matching cases.

Can someone please help.

awk '{printf $1" "}' infile

Hi All,

good morning.

I have an output file out of a native database in the following format..

term_id = "ABCDEF"
post_dat = "20090905"
hpr1_amt_beg = 30090000

term_id = "ade"
post_dat = "20090904"
hpr1_amt_beg = 3009123
 
term_id = "DEF"
post_dat = "20090903"
hpr1_amt_beg = 30090030

and i need it to be printed in the following format...

 
term_id post_dat hpr1_amt_beg
ABCDEF 20090905 30090000 
ADE    20090904 30090030
DEF    20090903 30090030

I tried using awk & sed...but somehow the output format is not exactly coming as above.Can somebody help me out here...Thanks mates.

can you show us what you have tried?

Hi Malcolm,

The following is the syntax which i tried a while ago...

 
awk '{FS = "="}{printf $1" "$2" "}' test.out >> test1.out

Here the test.out is the input file which contains the contents

term_id = "ABCDEF"
post_dat = "20090905"
hpr1_amt_beg = 30090000
term_id = "ade"
post_dat = "20090904"
hpr1_amt_beg = 3009123
term_id = "DEF"
post_dat = "20090903"
hpr1_amt_beg = 30090030

..and i get the output as follows in a single line...

 
term_id   "ABCDEF" post_dat   "20090905" hpr1_amt_beg   30090000   term_id   "ade" post_dat   "20090904" hpr1_amt_beg   3009123   term_id   "DEF" post_dat   "20090903" hpr1_amt_
beg   30090030

i believe somewhere i have to break the line when the "term_id" column starts to print it in the next line.I am doing trial and error.i hope i will crack it soon.

check this Post, it will help you...


Thanks mate... i will try it and let it know in the thread.

---------- Post updated at 04:38 PM ---------- Previous update was at 10:49 AM ----------

Thanks mate..it worked.

This is the snippet///

awk '/term_id/ { printf $3 " " };/post_dat/ {printf $3 " "} ;/hpr1_amt_beg/ {printf $3 "\n"} ;' test.out