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
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
Debian: doubt in "top" %CPU and "sar" output jaduks Debian 0 09-12-2007 08:05 AM
Weird problem with output from "date '+3600*%H+60*%M+%S' " m223464 Shell Programming and Scripting 5 02-16-2006 12:22 PM
Unix "at" / "Cron" Command New Problem...Need help Mohanraj UNIX for Dummies Questions & Answers 3 01-26-2006 08:08 PM
Sorting "ls" output on more than 1 column Nicol UNIX for Dummies Questions & Answers 1 09-20-2005 07:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-31-2006
ganapati's Avatar
ganapati ganapati is offline
Registered User
  
 

Join Date: Jul 2006
Location: Mysore
Posts: 125
Post 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
  #2 (permalink)  
Old 07-31-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
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.
  #3 (permalink)  
Old 08-01-2006
ganapati's Avatar
ganapati ganapati is offline
Registered User
  
 

Join Date: Jul 2006
Location: Mysore
Posts: 125
Post

Thanks very much,

I tried this code

sort -k 2,2 file.txt
  #4 (permalink)  
Old 08-01-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
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

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:09 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