LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-29-2008, 07:36 AM   #1
bioinformatics_guy
Member
 
Registered: Aug 2008
Posts: 54

Rep: Reputation: 15
Can I sort by different criteria?


If I had a tabdelimited file of the following form:

12234 493838 29284858 1938392
29383 484484 48404044 4849449
58595 484848 49494994 4848484
...

Where there is a tab between the numbers on the same line and a newline at the end of the 4th number set. What I'd like to know is, can I sort by say the 2nd or 3rd column? Also (with the above example it might be hard to explain but...) can I sort by the like 3rd number of the 1st set of numbers.

A better example would be

DDD_AAA_123 1313 44213 53453
DDD_RRR_456 3893 38383 38383
AAA_TTT_454 3938 38585 10191

Say I wanted to sort by number on the first string, the '_###' number. Is this possible with sort?
 
Old 09-29-2008, 08:05 AM   #2
jb_get
Member
 
Registered: Sep 2008
Location: America
Distribution: Debian
Posts: 33

Rep: Reputation: 16
Yes, you can do that. You will have to use something along the lines of this:

Code:
$ sort -t'|' -k2 nameoffile
with -t being the delimiter and -k# means the colomn

Last edited by Tinkster; 09-16-2010 at 01:20 PM.
 
Old 09-29-2008, 08:21 AM   #3
bioinformatics_guy
Member
 
Registered: Aug 2008
Posts: 54

Original Poster
Rep: Reputation: 15
What does the '|' stand for? Is that signifying that the -t is the delimiter?
 
Old 09-29-2008, 08:37 AM   #4
jb_get
Member
 
Registered: Sep 2008
Location: America
Distribution: Debian
Posts: 33

Rep: Reputation: 16
'|' means that whatever is inside the quotes is the delimiter. and in your case actually you dont have to use a delimiter since a space is the default delimiter if none is selected. so just use the column option and see what that turns out.

here is the man page for sort:

http://www.ss64.com/bash/sort.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Eligibility criteria kaz2100 LQ Suggestions & Feedback 3 04-28-2007 08:12 PM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 09:40 PM
Changes to search criteria ??? bigjohn LQ Suggestions & Feedback 2 07-27-2004 09:12 PM
Installation criteria puniti Linux - Networking 1 07-31-2003 04:43 AM
Search criteria finegan LQ Suggestions & Feedback 3 04-22-2002 05:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration