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

HELP SORTING OUTPUT INTO COLUMNS 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I would like to sort the output of a file into columns because all lines of the output are not the same width and I would like to have the values for each column line up. Any help would be greatly appreciated.

Thanks,

John
 
Awk will do it :
Eg a 4 column record line, where field separator is 1 space
awk ' {printf("%Ns %Ns %Ns %Ns",$1,$2,$3,$4) } ' infile > outfile
where N is a decimal value of column width you require.
HTH
Dickie Bird (:)-)))
 
Thanks, Dickie Bird!! That works well, however it would be better if I could align the first column to the left. Any chance you could help me out with that?

Thanks,

John
 
Yep - put a minus sign after % and before 'N'
eg awk ' {printf("%-Ns %Ns %Ns %Ns",$1,$2,$3,$4) } ' infile > outfile
Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top