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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help needed to sort multiple columns in one file ahjiefreak UNIX for Dummies Questions & Answers 1 12-07-2007 05:50 AM
need help in sort ali560045 Shell Programming and Scripting 2 12-04-2007 07:38 AM
Help needed to sort file inditopgun Shell Programming and Scripting 2 09-27-2007 06:40 PM
help needed with sort. pipe and popen() the_learner UNIX for Dummies Questions & Answers 7 05-21-2007 07:24 PM
sort enuenu UNIX for Dummies Questions & Answers 2 03-14-2007 04:59 AM

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 01-20-2006
Andysundar Andysundar is offline
Registered User
  
 

Join Date: Dec 2004
Posts: 4
Sort - Help Needed

Hi,

I am facing a small problem while I am doing the sort.

Problem Definition:

I have a file which has the following data.
>cat test.dat
zxzxc
asdasd
qwaxcZa
qwaxcA


When I do a sort on this file.

the result set is

asdasd
qwaxcA
qwaxcZa

zxzxc

But, we need to sort by using the first 5 charaters only.

The desired output should be

asdasd
qwaxcZa
qwaxcA

zxzxc

Can we do the sort by using only the first five characters of the field.

Any help is highly appriciated.

thanks
Anand
  #2 (permalink)  
Old 01-20-2006
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
Registered User
  
 

Join Date: May 2002
Location: India
Posts: 295
Hi Anand,

Try this command
sort -k1.1,1.5 yourfilename

It means sort based on field 1 starting at first character to field 1 5th character.


Note: not tested
  #3 (permalink)  
Old 01-20-2006
Andysundar Andysundar is offline
Registered User
  
 

Join Date: Dec 2004
Posts: 4
Thanks for the reply, but its not working.

Still it gives the following output only.

> sort -k1.1,1.5 test.dat
asdasd
qwaxcA
qwaxcZa
zxzxc
  #4 (permalink)  
Old 01-20-2006
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Try it with numeric option - possibly -g or -n (yea, I know it doesn't make sense)

Linux: sort -g -k1.1,1.5 yourfile
Solaris: sort -n -k1.1,1.5 yourfile
  #5 (permalink)  
Old 01-23-2006
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,418
Try this :

cat -n test.dat | sort -k2,2.5 -k1,1n | cut -f2-
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 04:44 AM.


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