The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh - test if string contains alphanumeric... tugger Shell Programming and Scripting 3 10-16-2007 04:23 AM
alphanumeric comparision rakeshou Shell Programming and Scripting 3 09-27-2007 11:32 AM
AlphaNumeric String Operations lakshmikanth UNIX for Dummies Questions & Answers 3 01-05-2007 06:55 AM
matching alphanumeric string sskb Shell Programming and Scripting 4 12-12-2001 10:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-29-2006
gefa gefa is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 72
sort command - alphanumeric

I have a file I'm trying to sort such as

fred1
fred2
fred10
fred11
...

when I sort I get

fred1
fred10
fred11
fred2
...

using sort can any give me the syntax to sort this is dict order

e.g.,

fred1
fred2
fred10
fred11

I've done is in the past but can't for the life of me remember the syntax!
  #2 (permalink)  
Old 08-29-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
If they all actually begin with "fred":
Code:
echo "fred1
fred2
fred10
fred11" | sort -k1.5n
Yields
Code:
fred1
fred2
fred10
fred11
  #3 (permalink)  
Old 08-29-2006
dsravan dsravan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 186
Glenn,

Can you please tell what does sort -k1.5n mean? I think you are specifying the key as fred but what does -k.5n signify?
  #4 (permalink)  
Old 08-29-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Let's see if I can explain this correctly (I'm still working on my sort skills):

-k to set the key
1.5 means that the 5th character of the 1st field is the start of the sort field
n means that this field is to be treated as numeric

Anyone else feel free to correct that explanation if it's not accurate.
  #5 (permalink)  
Old 08-30-2006
gefa gefa is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 72
Many thanks Glenn, works perfectly I knew it could be done but not using sort very often my mind went blank !
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0