Sorting problem "sort -k 16,29 sample.txt > output.txt" | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Sorting problem "sort -k 16,29 sample.txt > output.txt"

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-31-2006
ganapati's Avatar
ganapati ganapati is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 17 October 2012, 10:54 AM EDT
Location: Mysore
Posts: 148
Thanks: 2
Thanked 0 Times in 0 Posts
Java Sorting problem "sort -k 16,29 sample.txt > output.txt"

Hi all,

Iam trying to sort the contents of the file based on the position of the file.
Example:

$cat sample.txt
0101020060731 ## Header record
1c1 Berger Awc ANP20070201301 4000.50
1c2 Bose W G ANP20070201609 6000.70
1c2 Andy CK ANP20070201230 28000.00
1c3 Bharg ANP20070201847 9000.80
1c3 Peter Neid ANP20070201109 2000.50
1c3 Ralf Tiger ANP20070201365 4000.10
900006 ## Trailer record

Where ANP*********** is the policy number and starts in the file from 16th position. I need to sort based on these policy numbers.
Iam using the "Sort" Option as below:

sort -k 16,29 sample.txt > output.txt

But it is not sorting based on Policy numbers.
Could any one help me to fix it.

Many Thanks and Regards,
Ganapati
Sponsored Links
    #2  
Old 07-31-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 23 July 2014, 4:36 PM EDT
Location: NM
Posts: 10,153
Thanks: 268
Thanked 781 Times in 731 Posts
Turn off field separation by using a field sep character that does not occur in any record. Try the : character, then everything is in field1

Code:
sort -t: -k 1.16,1.29 sample.txt > output.txt

This sorts character positions 16-29.
Sponsored Links
    #3  
Old 08-01-2006
ganapati's Avatar
ganapati ganapati is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 17 October 2012, 10:54 AM EDT
Location: Mysore
Posts: 148
Thanks: 2
Thanked 0 Times in 0 Posts
Java

Thanks very much,

I tried this code

sort -k 2,2 file.txt
    #4  
Old 08-01-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 23 July 2014, 4:36 PM EDT
Location: NM
Posts: 10,153
Thanks: 268
Thanked 781 Times in 731 Posts
the -k option requires m.n
m= field number
n = character position

You are missiing character positions.

Use -k2.1,2.10 or something.
Sponsored Links
Closed Thread

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
Could interrupt disabled cause "opreport error: No sample file found"? manustone Red Hat 0 03-21-2012 09:32 AM
Meaning of "b" modifier in "sort" command wjssj Shell Programming and Scripting 3 02-04-2011 10:56 AM
Problem in understanding the output of errpt -d H -T PERM -s `date +"%m%d%H00%y"` Sounddappan AIX 0 07-09-2010 10:32 AM
"Join" or "Merge" more than 2 files into single output based on common key (column) Katabatic Shell Programming and Scripting 1 05-20-2010 11:41 AM
Sorting "ls" output on more than 1 column Nicol UNIX for Dummies Questions & Answers 1 09-20-2005 07:37 AM



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