The UNIX and Linux Forums  


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




Thread: sort csv file
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 02-11-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092
sed+sort

Hi,

This one should be ok for you.


Code:
sed '
s/\([0-9]*\)-jan-\([0-9]*\)/\201\1/;
s/\([0-9]*\)-feb-\([0-9]*\)/\202\1/;
s/\([0-9]*\)-mar-\([0-9]*\)/\203\1/;
s/\([0-9]*\)-apr-\([0-9]*\)/\204\1/;
s/\([0-9]*\)-may-\([0-9]*\)/\205\1/;
s/\([0-9]*\)-jun-\([0-9]*\)/\206\1/;
s/\([0-9]*\)-jul-\([0-9]*\)/\207\1/;
s/\([0-9]*\)-aug-\([0-9]*\)/\208\1/;
s/\([0-9]*\)-sep-\([0-9]*\)/\209\1/;
s/\([0-9]*\)-oct-\([0-9]*\)/\210\1/;
s/\([0-9]*\)-nov-\([0-9]*\)/\211\1/;
s/\([0-9]*\)-dec-\([0-9]*\)/\212\1/
' filename > filename.temp
sort -t"," +2 filename.temp | cut -d"," -f1,2,3
rm filename.temp