1754292 Members
3832 Online
108813 Solutions
New Discussion юеВ

Reformatting text

 
SOLVED
Go to solution
Ciro_gft
New Member

Reformatting text

Hi all,

I received the following output after an SQL script:

TradeId CommonRef MirrorId TermAssignStatus Book
P/S Customer Currency Curve Effective Date
Maturity Date Notional Amount Product Type Rate
Trade Status Sec Amount Trade Date Trader ParentId
Last Update

That's actually an excerpt, there are 22k entries with this format. Instead of those 8 columns what I'd need a single line with every entry being it's own column. I've attached a text file with the original format and how I'd like it reformatted.

I've been trying awk but I can't seem to find the way to do it, can someone give me a tip on this?


Thanks and Regards,

Ciro
7 REPLIES 7
Ciro_gft
New Member

Re: Reformatting text

Sprry I didn't include the file, here it is.
Suraj K Sankari
Honored Contributor

Re: Reformatting text

Hi,
suppose your data stored on a file "d"
In the command prompt write this line,

#awk '{ printf "%s", $0 }'
if you want your output into another file then do like this
#awk '{ printf "%s", $0 }'outputfile

Suraj
Ciro_gft
New Member

Re: Reformatting text


Hi Suraj,

Thanks for your help.
Dennis Handly
Acclaimed Contributor
Solution

Re: Reformatting text

It appears you want to combine 5 lines into one, for 22 K entries?
awk '{
getline L2
getline L3
getline L4
getline L5
print $0, L2, L3, L4, L5 }' file
Ciro_gft
New Member

Re: Reformatting text


Hi Dennis,


Yes that's what I needed, thanks very much.
James R. Ferguson
Acclaimed Contributor

Re: Reformatting text

Hi Ciro:

To combine multiple lines into one you can use 'paste'.

# paste -d" " - - - - - < myfile

See the manpages for more information.

Regards!

...JRF...
OldSchool
Honored Contributor

Re: Reformatting text

from JRF: "# paste -d" " - - - - - < myfile"

thats an application of paste / redirection I'd never encountered before. nifty!