LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-13-2009, 01:27 PM   #1
KBriggs
Member
 
Registered: Jun 2009
Posts: 35

Rep: Reputation: 15
Bash script sorting multple columns together


Hey,

I have a file that contains anywhere from 2 to 6 columns of data, which I need to sort based on one of these columns. Te catch is that I need all of the lines to stay together through the sorting, ei, the 6th entry in all columns has to stay together even though I am sorting based only one one column.

For example:

1 4 8
4 2 9
2 3 7
8 8 1

If sorted in ascending order by second column would have to look like:

4 2 9
2 3 7
1 4 8
8 8 1

Now, I can do this in C, I know how, but I -really- don't want to because it is a ridicluous pain in the the ass to do this in a low level language. So if someone can suggest a simple bash script (maybe using awk) that could do this it would be greatly appreciated.

TIA
Kyle
 
Old 08-13-2009, 01:35 PM   #2
Nevahre
LQ Newbie
 
Registered: Aug 2009
Posts: 21

Rep: Reputation: 16
sort can do that: sort -k2 yourfile
 
Old 08-13-2009, 01:59 PM   #3
KBriggs
Member
 
Registered: Jun 2009
Posts: 35

Original Poster
Rep: Reputation: 15
Heh, just figured that one out. Thanks
 
  


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
Bash script for sorting and renaming multiple mp3 files by id3 tags simonloach Linux - General 8 02-16-2013 10:07 AM
Bash script for sorting out FSTAB & mount points ? Sparxz Linux - Newbie 1 05-30-2009 08:04 PM
bash scripting: sorting and using using multiple files in a script daberkow Linux - Newbie 8 05-28-2009 10:24 AM
sorting columns in bash twistadias Linux - Newbie 8 08-25-2008 01:22 AM
Bash - How can you list 2 arrays in columns zak111 Programming 12 07-23-2007 12:27 PM


All times are GMT -5. The time now is 04:51 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration