![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binary or ascii file | u263066 | Shell Programming and Scripting | 6 | 08-08-2008 08:19 AM |
| Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names | nikosey | Shell Programming and Scripting | 6 | 07-30-2008 06:46 PM |
| How to convert English text file to ASCII File? | laknar | Shell Programming and Scripting | 1 | 07-23-2008 06:37 AM |
| Hex characters of ascii file | budrito | HP-UX | 2 | 08-10-2005 07:26 PM |
| ASCII file | sherbet808 | UNIX Desktop for Dummies Questions & Answers | 1 | 06-13-2003 06:46 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sorting an ascii file
I would like to sort a large ascii file. Primary sort on the 1st column, and secondary sort on the second column. The file consists of 10 rows of header text and then thousands of rows with 6 columns. I want to sort all of the rows by the first column and second column. As an example, here is example.asc:
Header text 256 5000 4008 300 5000 4008 256 5006 4008 I would also like to know the minimum and maximum number for columns 1 and 2. Help is much appreciated! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I expanded the sample you provided to make the output more obvious.
Code:
> cat file13 Header text 256 5000 4018 300 5009 4008 256 5006 4008 200 6000 3000 128 5008 4009 > tail +2 file13 | sort -k1,2 128 5008 4009 200 6000 3000 256 5000 4018 256 5006 4008 300 5009 4008 The sort -k1,2 sorts on the first field then the second To get the high and low values: Code:
> tail +2 file13 | cut -d" " -f1 | sort | head -1 128 > tail +2 file13 | cut -d" " -f1 | sort | tail -1 300 > tail +2 file13 | cut -d" " -f2 | sort | head -1 5000 > tail +2 file13 | cut -d" " -f2 | sort | tail -1 6000 |
|
#3
|
|||
|
|||
|
Thanks!
|
|||
| Google The UNIX and Linux Forums |