Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple rows to one row many columns 1

Status
Not open for further replies.

AnotherAlan

Technical User
Feb 10, 2006
362
GB
Hi,

I have a sample file produced from a sql statement that I would like to format into something excel readable. The data is produced for each hour so the full file will contain 36 rows minimum;

Sample data;
GTS 56
FID 78
WCK 92
GTS 50
FID 70
WCK 136
..
..
..
GTS 45
e.tc.

What I would like is this;
GTS 56 50 .. .. 45
FID 78 70 .. .. 32
WCK 92 136 .. .. 78

I'm struggling with it though; what i've come up with so far is this;

grep GTS output.log1 | awk 'NR==1 {printf "%s ", $1} {printf "%s ", $2} END {printf "\n"}'

but this is not elegant and would involve multiple greps and a little further processing to get the format correct.
I've tried using awk pattern matching but it gave some spurious result;

awk '/GTS/ {printf "%s ", $1} {printf "%s ", $2} END {printf "\n"}' output.log1

GTS 56 78 92 GTS 50 70 136

Any suggestions on how I could go about improving this?
All help appreciated.

Thanks
Alan



 
A starting point:
Code:
awk '{a[$1]=a[$1]" "$2}END{for(i in a)print i,a[i]}' output.log1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, once again.
I dont think I'll ever get my head around awk!

Much obliged
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top