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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transposing data 1

Status
Not open for further replies.

BetNackup

Technical User
Feb 15, 2005
6
0
0
US
Hello All,

Those who are scripting experts will probably find this easy, but could somebody point me in the right direction.

I have a report that I would like to import into excel for each record (which there are many) that looks as following:

Record1

Name: Bob
Date: 1/1/2004
Amount:3456
Time: 12:00pm

Record 2
Name: Mary
Date: 2/1/1974
Amount:3000
Time: 5:00pm

...

Record n
Name: x
Date: y
Amount: z
Time: p

I am trying to write a shell script (sh) that will give me a single comma delimited line for each record. Any ideas, as I haven't done anything like this before?

Many thanks

 
A starting point:
awk -F: '
BEGIN{printf "Name,Date,Amount,Time\n"}
NF>1 && $1!="Time"{printf "%s,",$2}
$1=="Time"{printf "%s:%s\n",$2,$3}
' /path/to/report > output.csv

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV!

Just what I needed, thanks for the assistance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top