The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-22-2009
s_adu s_adu is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
Delimited fields and formating

Hi

I am new to scripting. I have a file with following data

245|3|20090303456|3456
5072|34|20090304453|3546
245|28|20090304453|3547
5074|43|20090304453|3548

I want to format the file as below

245| 3|20090303456|3456
5072|34|20090304453|3546
245|28|20090304453|3547
5074|43|20090304453|3548

The main reason I want to do this is becase I want to sort the file using sort -n based on 1st 2 fields

If I do not reformat as above then sort -n will give

245|28|20090304453|3547
245|3|20090303456|3456
5072|34|20090304453|3546
5074|43|20090304453|3548

What I actually want is

245|3|20090303456|3456
245|28|20090304453|3547
5072|34|20090304453|3546
5074|43|20090304453|3548

Please help me.

Thanks and Regards
Adarsh