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
can someone tell me what im doing wrong here iago UNIX for Dummies Questions & Answers 2 09-10-2007 09:20 AM
what am i doing wrong iago UNIX for Dummies Questions & Answers 4 09-04-2007 07:27 AM
What’s wrong with the following? vrn UNIX for Dummies Questions & Answers 8 03-19-2006 09:09 PM
What was wrong ??? ksh sabercats Shell Programming and Scripting 11 02-27-2006 01:12 PM
Please tell me what do I do wrong here! bobo UNIX for Dummies Questions & Answers 4 02-20-2006 10:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-03-2008
Digby Digby is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
What's going wrong with sort?

Sort isn't behaving as I expect. Can someone tell me what's going on?
Incidentally, the infile was ordered by 'sort' previously.
Why is 101m_lig1_frag1 before 101m_lig1_frag12 but after 101m_lig1_frag11?

$infile...
101m_lig1_frag10 124 ...
101m_lig1_frag11 124 ...
101m_lig1_frag12 124 ...
101m_lig1_frag13 124 ...
101m_lig1_frag1 124 ...
101m_lig1_frag14 124 ...
101m_lig1_frag15 124 ...
101m_lig1_frag16 124 ...
101m_lig1_frag17 124 ...
101m_lig1_frag18 124 ...

100> sort $infile > $outfile

$outfile
101m_lig1_frag10 124 ...
101m_lig1_frag11 124 ...
101m_lig1_frag1 124 ...
101m_lig1_frag12 124 ...
101m_lig1_frag13 124 ...
101m_lig1_frag14 124 ...
101m_lig1_frag15 124 ...
101m_lig1_frag16 124 ...
101m_lig1_frag17 124 ...
101m_lig1_frag18 124 ...
  #2 (permalink)  
Old 09-03-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
use sort -d infile..
  #3 (permalink)  
Old 09-03-2008
Digby Digby is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Thanks, but I'm still getting the same result... wierd!

daisy 1807>cat head.fps | awk '{print $1,$2,"..."}' | sort -d
101m_lig1_frag10 124 ...
101m_lig1_frag11 124 ...
101m_lig1_frag1 124 ...
101m_lig1_frag12 124 ...
101m_lig1_frag13 124 ...
101m_lig1_frag14 124 ...
101m_lig1_frag15 124 ...
101m_lig1_frag16 124 ...
101m_lig1_frag17 124 ...
101m_lig1_frag18 124 ...
  #4 (permalink)  
Old 09-03-2008
RahulJoshi's Avatar
RahulJoshi RahulJoshi is offline
Registered User
  
 

Join Date: Aug 2008
Location: PUNE
Posts: 98
sort -n
it may solv ur problem
  #5 (permalink)  
Old 09-03-2008
Digby Digby is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Quote:
Originally Posted by RahulJoshi View Post
sort -n
it may solv ur problem
Thanks, but I've already tried it. I get the same output as above.
  #6 (permalink)  
Old 09-03-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,301
You can give this a try:

Code:
awk '{print substr($1,15)" "$0}' infile | sort -n | cut -d" " -f2-
Regards
  #7 (permalink)  
Old 09-03-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 573
Quote:
Originally Posted by Digby View Post
Sort isn't behaving as I expect. Can someone tell me what's going on?
Incidentally, the infile was ordered by 'sort' previously.
Why is 101m_lig1_frag1 before 101m_lig1_frag12 but after 101m_lig1_frag11?

$infile...
101m_lig1_frag10 124 ...
101m_lig1_frag11 124 ...
101m_lig1_frag12 124 ...
101m_lig1_frag13 124 ...
101m_lig1_frag1 124 ...
101m_lig1_frag14 124 ...
101m_lig1_frag15 124 ...
101m_lig1_frag16 124 ...
101m_lig1_frag17 124 ...
101m_lig1_frag18 124 ...

100> sort $infile > $outfile

$outfile
101m_lig1_frag10 124 ...
101m_lig1_frag11 124 ...
101m_lig1_frag1 124 ...
101m_lig1_frag12 124 ...
101m_lig1_frag13 124 ...
101m_lig1_frag14 124 ...
101m_lig1_frag15 124 ...
101m_lig1_frag16 124 ...
101m_lig1_frag17 124 ...
101m_lig1_frag18 124 ...
This is just normal behaviour of sort . You can't do a sort -n as the numbers belongs to the part of string of alphabets.

One option would be:

Code:
for each in $(sed 's/101m_lig1_frag\(.*\) 124\(.*\)/\1/' infile | sort -n); do grep  "^101m_lig1_frag$each " infile; done
Output:

Quote:
101m_lig1_frag1 124 ...
101m_lig1_frag10 124 ...
101m_lig1_frag11 124 ...
101m_lig1_frag12 124 ...
101m_lig1_frag13 124 ...
101m_lig1_frag14 124 ...
101m_lig1_frag15 124 ...
101m_lig1_frag16 124 ...
101m_lig1_frag17 124 ...
101m_lig1_frag18 124 ...
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 02:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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