LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 12-08-2007, 04:04 PM   #1
Yogiz
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Rep: Reputation: 0
Help with sorting a file


Hi there,

I would like to ask how I could sort this nam input file;

Code:
+ 2.47 4 3 cbr 500 ------- 3 4.0 1.1 294 989
+ 2.47 1 2 cbr 500 ------- 2 1.0 5.0 394 990
+ 2.47 2 3 cbr 500 ------- 2 1.0 5.0 313 828
+ 2.471 3 2 cbr 500 ------- 3 4.0 1.1 292 985
+ 2.472 3 5 cbr 500 ------- 1 0.0 5.0 233 600
so that the output file is in ascending order by last column "989", "990" etc

Code:
+ 2.472 3 5 cbr 500 ------- 1 0.0 5.0 233 600
+ 2.47 2 3 cbr 500 ------- 2 1.0 5.0 313 828
+ 2.471 3 2 cbr 500 ------- 3 4.0 1.1 292 985
+ 2.47 4 3 cbr 500 ------- 3 4.0 1.1 294 989
+ 2.47 1 2 cbr 500 ------- 2 1.0 5.0 394 990
Thanks in advance for your input.

Yogiz
 
Old 12-08-2007, 04:17 PM   #2
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
Use sort(1) utility
 
Old 12-08-2007, 04:17 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If the number of columns is fixed, e.g. each rows have always 12 fields, you can use sort with option -k to specify the position of the field to be sorted:
Code:
sort -n -k 12 input_file
 
Old 12-08-2007, 04:31 PM   #4
Yogiz
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Awsome thanks for that.

How would I go on about then extracting just the first column into a new file?
 
Old 12-08-2007, 04:33 PM   #5
Yogiz
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Awsome thanks for that.

How would I go on about then extracting just the second column into a new file?
For example;

2.472
2.47
2.471
2.47
2.47
 
Old 12-08-2007, 04:41 PM   #6
Yogiz
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Got it used

awk '{print $2}' filename > output

Love Linux
 
  


Reply



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
Linux File Sorting linuxgodrh Linux - General 7 08-01-2007 09:33 AM
sorting a file in shell script shmuel_orgad Programming 11 05-20-2006 08:16 PM
Sorting data in output file lluciano Linux - General 2 08-19-2005 10:37 AM
Sorting a file containing dates subu_s Linux - General 2 06-03-2004 01:07 PM
File sorting problem Kerridis Linux - General 3 03-08-2004 10:44 PM

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

All times are GMT -5. The time now is 09:19 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
Open Source Consulting | Domain Registration