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 12:19 PM
Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names nikosey Shell Programming and Scripting 6 07-30-2008 10:46 PM
How to convert English text file to ASCII File? laknar Shell Programming and Scripting 1 07-23-2008 10:37 AM
Hex characters of ascii file budrito HP-UX 2 08-10-2005 11:26 PM
ASCII file sherbet808 UNIX Desktop for Dummies Questions & Answers 1 06-13-2003 10:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-07-2008
shes shes is offline
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!
  #2 (permalink)  
Old 10-07-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
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

  #3 (permalink)  
Old 10-08-2008
shes shes is offline
Registered User
  
 

Join Date: Oct 2008
Location: Norway
Posts: 2
Thanks!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0