LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-19-2013, 01:35 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
sort third column


how do i sort these by the number
like if i was to delimit this with awk -F"." how do i sort this by the third column?

Code:
casper@cprvdr02 foos $ ls -ltr | grep commands
-rw-r--r-- 1 root     root       605 Jan  7 13:15 cprvdr02.7.commands
-rw-r--r-- 1 root     root       259 Jan  7 13:15 cprvdr02.6.commands
-rw-r--r-- 1 root     root       329 Jan  7 13:15 cprvdr02.5.commands
-rw-r--r-- 1 root     root       277 Jan  7 13:15 cprvdr02.4.commands
-rw-r--r-- 1 root     root       627 Jan  7 13:15 cprvdr02.1.commands
-rw-r--r-- 1 root     root       212 Jan 10 11:15 cprvdr02.3.commands
-rw-r--r-- 1 root     root       205 Jan 10 11:16 cprvdr02.8.commands
-rw-r--r-- 1 root     root       324 Jan 14 19:05 cprvdr02.2.commands
 
Old 01-19-2013, 02:01 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
With field seperator as ".", third column in that case will be "commands... commands... commands...".
Anyway, you can sort any column with sort command, as:-
Code:
~$ sort -t "." -n -k2 infile.txt
For understanding,
Code:
~$ sort -t "<field-seperator>" -n -k<column-no> <input-file>
Where, -n option is used for numeric sorting, which in your case, with FS as ".", column 2, not third.

For more details, refer: man sort

Last edited by shivaa; 01-19-2013 at 02:03 PM.
 
Old 01-19-2013, 03:24 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
They are already sorted, if you don't sort them by modification time. Or am I missing something?
Code:
ls -l *.commands
 
  


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
sort by column with null value sophiesu Linux - Newbie 1 01-04-2012 12:34 PM
how to sort the 2nd column on the basis of first column without repeating the value ? zediok Linux - Newbie 15 12-20-2011 11:48 AM
unix sort on column PMP Linux - Newbie 3 08-24-2009 06:42 AM
sort on a single column? baidym Programming 3 01-03-2009 08:46 AM


All times are GMT -5. The time now is 09:30 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