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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-31-2006
ganapati's Unix or Linux Image
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 Unix or Linux Image
Sponsored Links
    #2  
Old Unix and Linux 07-31-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 29 March 2015, 10:00 AM EDT
Location: NM
Posts: 10,408
Thanks: 325
Thanked 854 Times in 793 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 Unix and Linux 08-01-2006
ganapati's Unix or Linux Image
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 Unix and Linux 08-01-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 29 March 2015, 10:00 AM EDT
Location: NM
Posts: 10,408
Thanks: 325
Thanked 854 Times in 793 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 06:22 PM.