Link to home
Start Free TrialLog in
Avatar of jjackson2004
jjackson2004Flag for United States of America

asked on

sort columns in text file

need to sort the following txt file on the second column.
sort +1 -2 body.txt did not work, nor did sort -k 35,50 body.txt nor did sort -t\t +1 -2 body.txt

Oracle Programming                 Sunderraman      in                
Unix for Programmers and Users     Glass            in                
Java Programming                   King             out   10/12/99    Smith
C Programming                      King             out   4/1/10      Jackson
Database Systems                   ElMasri          out   12/5/99     Jones
Discrete Math                      Jackson          in                
Extreme Intelligence               Jackson          in  

the first field is 35 chars, second is 15 chars.

thanks
Avatar of Bryan Butler
Bryan Butler
Flag of United States of America image

This worked for me:

> Sort -k 35,50 body.txt
C Programming                      King             out   4/1/10      Jackson
Database Systems                   ElMasri          out   12/5/99     Jones
Discrete Math                      Jackson          in
Extreme Intelligence               Jackson          in
Java Programming                   King             out   10/12/99    Smith
Oracle Programming                 Sunderraman      in
Unix for Programmers and Users     Glass            in

What error or output did you get?
Avatar of jjackson2004

ASKER

no error, it just would not sort on anything other than the beginning of the line.
ASKER CERTIFIED SOLUTION
Avatar of shajithchandran
shajithchandran
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it would be good if while generating the this file, separate field with | rather than space. That way it would be easy to sort it.
i just changed the field separator to : which doesnt exist in the line.. so the whole line becomes the first field. Than i sorted it based on the 35character to get sort based on the field that you were interested in.