Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-04-2012
Registered User
 

Join Date: Sep 2011
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Help to sort out... Possible use of sort command

I have an input like

4.3.6.66
4.3.6.67
4.3.6.70
4.3.6.25
4.3.6.15
4.3.6.54
4.3.6.44
4.3.6.34
4.3.6.24
4.3.6.14
4.3.6.53
4.3.6.43
4.3.6.49
4.3.6.33
4.3.6.52
4.3.6.19
4.3.6.58
4.3.6.42
4.3.6.48
4.3.6.32
4.3.6.38
4.3.6.22
4.3.6.12
4.3.6.51
4.3.6.18
4.3.6.47
4.3.6.31
4.3.6.37
4.3.6.21
4.3.6.27
4.3.6.50
4.3.6.17
4.3.6.46
4.3.6.30
4.3.6.36
4.3.6.20
4.3.6.26
4.3.6.65
4.3.6.16
4.3.6.45
4.3.6.35
4.3.6.82
4.3.6.88
4.3.6.87
4.3.6.86
4.3.6.84
4.3.6.83
4.3.6.89
4.3.6.91
4.3.6.92
4.3.6.93
4.3.6.94
4.3.6.96
4.3.6.100
4.3.6.99
4.3.6.102
4.3.6.103

someone please help me in sorting the above I/P. I used sort -n, but it doesn't work properly.

Please also explain how the command or option works there.
Sponsored Links
    #2  
Old 02-04-2012
Registered User
 

Join Date: Jun 2008
Location: Singapore
Posts: 186
Thanks: 3
Thanked 40 Times in 39 Posts

Code:
sed 's/\./ /g' input.txt | sort -n -k 4 | sed 's/ /./g'

Sponsored Links
    #3  
Old 02-04-2012
ahamed101's Avatar
root is god!!!
 

Join Date: Sep 2008
Location: India
Posts: 1,478
Thanks: 33
Thanked 382 Times in 377 Posts

Code:
sort -t'.' -nk4 infile

--ahamed
    #4  
Old 02-04-2012
Registered User
 

Join Date: Sep 2011
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Thanks Ahamed. It helped...
Sponsored Links
    #5  
Old 02-04-2012
Registered User
 

Join Date: Aug 2009
Location: New Jersey
Posts: 314
Thanks: 6
Thanked 66 Times in 54 Posts
GNU sort has -V option for sorting versions.
Sponsored Links
    #6  
Old 02-04-2012
Scrutinizer's Avatar
mother ate her
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 5,371
Thanks: 80
Thanked 1,107 Times in 1,011 Posts

Code:
sort -nt. -k1.1 -k2.2 -k3.3 -k4.4 infile

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sort command help Olivia UNIX for Dummies Questions & Answers 6 11-10-2011 04:47 PM
Is it Possible to sort a list of hexadecimal numbers using "sort" command? Kesavan Shell Programming and Scripting 9 08-21-2011 08:33 AM
Script to sort the files and append the extension .sort to the sorted version of the file pankaj80 UNIX for Advanced & Expert Users 3 06-07-2011 09:28 AM
How to Sort Floating Numbers Using the Sort Command? daniel.gbaena Shell Programming and Scripting 7 05-16-2010 11:20 AM
using cut command with sort hankooknara Shell Programming and Scripting 5 01-03-2007 02:06 AM



All times are GMT -4. The time now is 04:24 AM.