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 Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh - test if string contains alphanumeric... tugger Shell Programming and Scripting 3 10-16-2007 04:23 AM
alphanumeric comparision rakeshou Shell Programming and Scripting 3 09-27-2007 11:32 AM
AlphaNumeric String Operations lakshmikanth UNIX for Dummies Questions & Answers 3 01-05-2007 06:55 AM
sort command - alphanumeric gefa Shell Programming and Scripting 4 08-30-2006 10:36 AM
matching alphanumeric string sskb Shell Programming and Scripting 4 12-12-2001 10:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-15-2008
laxmi131 laxmi131 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 22
alphanumeric Sorting

Hi ,

I have a requirement where one column have to be sorted (delimiter is pipe)
for eg:
My input filed is as below
1|FIAT|0010103|23011|01/01/2000|31/12/9999|1.15
2|232|613|1
2|234|743|1
2|234|793|1
2|234|893|1
1|FIAT|0010103|23012|01/01/2000|31/12/9999|1.15
2|230|006|0
2|230|106|0
2|230|116|0
2|230|716|0
1|FIAT|0010103|113013|01/01/1996|31/12/9999|1.15
2|231|966|0
2|232|747|0
1|FIAT|0010103|123014|01/01/2000|31/12/9999|1.15
2|232|717|0
2|232|718|0
2|232|728|0
2|232|818|0

I need to do alphanumeric (dictionary) sort for all the columns marked in red for only thoes record which start with '1'. Record '1' should followed by all thoes which start with '2'

and my desired out put is

1|FIAT|0010103|113013|01/01/1996|31/12/9999|1.15
2|231|966|0
2|232|747|0
1|FIAT|0010103|123014|01/01/2000|31/12/9999|1.15
2|232|717|0
2|232|718|0
2|232|728|0
2|232|818|0
2|232|827|0
2|232|828|0
1|FIAT|0010103|23011|01/01/2000|31/12/9999|1.15
2|232|613|1
2|234|743|1
2|234|793|1
2|234|893|1
1|FIAT|0010103|23012|01/01/2000|31/12/9999|1.15
2|230|006|0
2|230|106|0
2|230|116|0
2|230|716|0

Is ther any command to sort such kind of input data?
  #2 (permalink)  
Old 12-15-2008
laxmi131 laxmi131 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 22
sorry my desired output is as below :
1|FIAT|0010103|113013|01/01/1996|31/12/9999|1.15
2|231|966|0
2|232|747|0
1|FIAT|0010103|123014|01/01/2000|31/12/9999|1.15
2|232|717|0
2|232|718|0
2|232|728|0
2|232|818|0
1|FIAT|0010103|23011|01/01/2000|31/12/9999|1.15
2|232|613|1
2|234|743|1
2|234|793|1
2|234|893|1
1|FIAT|0010103|23012|01/01/2000|31/12/9999|1.15
2|230|006|0
2|230|106|0
2|230|116|0
2|230|716|0
  #3 (permalink)  
Old 12-15-2008
laxmi131 laxmi131 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 22
sorry my desired output is as below :
1|FIAT|0010103|113013|01/01/1996|31/12/9999|1.15
2|231|966|0
2|232|747|0
1|FIAT|0010103|123014|01/01/2000|31/12/9999|1.15
2|232|717|0
2|232|718|0
2|232|728|0
2|232|818|0
1|FIAT|0010103|23011|01/01/2000|31/12/9999|1.15
2|232|613|1
2|234|743|1
2|234|793|1
2|234|893|1
1|FIAT|0010103|23012|01/01/2000|31/12/9999|1.15
2|230|006|0
2|230|106|0
2|230|116|0
2|230|716|0
  #4 (permalink)  
Old 12-15-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
Code:
perl -F'\|' -ane'
  @F > 6 and $_{$k = $F[3]} = $_ or
  $_{$k} .= $_;
  print map $_{$_}, sort keys %_ if eof
  ' infile
  #5 (permalink)  
Old 12-15-2008
laxmi131 laxmi131 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 22
Hi radoulov,

Thanks for the reply,but i am not able to understand what the script is doing can you please expalin me .I am sorry i am new to unix hence unable to understand the above command
  #6 (permalink)  
Old 12-15-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
Did you try it? Is it working?
You just need to run that command in your terminal, using your data file name instead of infile.
  #7 (permalink)  
Old 12-15-2008
laxmi131 laxmi131 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 22
Yes i have tried the command and its working
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 09:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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