The UNIX and Linux Forums  

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
sort command naamas03 UNIX for Dummies Questions & Answers 2 11-11-2007 11:25 AM
the sort command wickbc UNIX for Dummies Questions & Answers 0 11-08-2007 03:30 PM
Sort command... Indalecio Shell Programming and Scripting 5 06-25-2007 06:40 AM
SORT COMMAND help ndoggy020 UNIX for Dummies Questions & Answers 2 06-05-2007 02:45 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 11-22-2004
aman_aj aman_aj is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 2
Unhappy regarding sort command.

hi,

In UNIX I want a sort records in a file based on the certain position in the record as the key in the file.

Now if certain 2 records have the same record then the out file should have the records as the First in First out i.e. in the same order in which they occur in the input file.

Say for e.g.

There are records in the input file

12345555555555677689870987
12345
12343

And I sort it based on the the keys 1-4 so then as per the sort I need

Output file


1234555555555555555
12345
12343

but the output I get is something like this

12343
12345
12445555555555555

i.e. it gets soreted on the next one records also if the key is the same which I don’t want it to happen.

Could someone please let me know if this is possible using the sort command in UNIX or any other way to do it.

Thanks
Aman.
  #2 (permalink)  
Old 11-22-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
This works for me

Code:
 sort -k 1.1,1.4 test.dat

  #3 (permalink)  
Old 11-22-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Quote:
Originally posted by jim mcnamara
This works for me

Code:
 sort -k 1.1,1.4 test.dat

That doesn't work for me. I get the same result as the OP. But this does the trick:

nl -ba < inputfile | sort -k2.1,2.4 -k1n | cut -f2- > outputfile
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 07:32 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