The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-07-2008
Registered User
 

Join Date: Oct 2008
Location: Norway
Posts: 2
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!
Reply With Quote
Forum Sponsor
  #2  
Old 10-07-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Wink The following is one approach to your questions

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 tail +2 skips to the 2nd line of input; for you, perhpas try +11
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
Reply With Quote
  #3  
Old 10-08-2008
Registered User
 

Join Date: Oct 2008
Location: Norway
Posts: 2
Thanks!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0