alphanumeric Sorting


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users alphanumeric Sorting
# 1  
Old 12-15-2008
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  
Old 12-15-2008
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  
Old 12-15-2008
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  
Old 12-15-2008
Code:
perl -F'\|' -ane'
  @F > 6 and $_{$k = $F[3]} = $_ or
  $_{$k} .= $_;
  print map $_{$_}, sort keys %_ if eof
  ' infile

# 5  
Old 12-15-2008
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  
Old 12-15-2008
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  
Old 12-15-2008
Yes i have tried the command and its working
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble with alphanumeric Sort

I have a lot of data that need to be sorted alphanumerically. I began using sort -du and it solved almost all my problems. However, when I encountered files with data like this it began to fail: /vol/close_eng_ice_0888 /vol/open_eng_ice_0890 /vol/open_eng_ice_08923 /vol/open_eng_ice_0893... (6 Replies)
Discussion started by: newbie2010
6 Replies

2. Shell Programming and Scripting

Sorting alphanumeric strings without a pattern

Good evening to all!! I'm facing this problem: I saved in a txt a list of files name (one txt for every folder): hello0.jpg hello1.jpg hello10.jpg hello11.jpg hello12.jpg hello13.jpg hello14.jpg hello15.jpg hello16.jpg hello17.jpg hello18.jpg hello19.jpg hello2.jpg hello20.jpg... (32 Replies)
Discussion started by: silver18
32 Replies

3. UNIX for Dummies Questions & Answers

Sorting of alphanumeric filenames..

Hi All, I want sort following files in ascending order. exp_installer_CC4160-file10.dmp exp_installer_CC4160-file11.dmp exp_installer_CC4160-file12.dmp exp_installer_CC4160-file13.dmp... (3 Replies)
Discussion started by: gramakrishna
3 Replies

4. UNIX for Dummies Questions & Answers

Parsing alphanumeric variables

Hi All, I have files with a column which has values and ranges, for example colA colB ERD1 3456 ERD2 ERD3 4456 I want to have the following output colA colB colC ERD1 3456 3456 ERD2 526887 526890 ERD3 4456 4456 Being a newbie to... (2 Replies)
Discussion started by: alpesh
2 Replies

5. Shell Programming and Scripting

Alphanumeric to integer

Hi folks, I have a value like A12,i could able to change this into integer using typeset as below typeset -i A12 But, I need your advice to change the values like 1A2 or 12A into integer. Thanks in advance. Thanks, Sathish (3 Replies)
Discussion started by: bsathishmca
3 Replies

6. UNIX for Dummies Questions & Answers

to find alphanumeric character

Hi All, I am having a data file which consists of lakhs of records in the below foramt: "1223323","4341341","discription aadfad" "3123123","5463456","discription aadfad" "2343324","6565767","discription asdfads" "A3423423","7957456","discription aadfad" "343453B","7957456","discription... (1 Reply)
Discussion started by: abhi_123
1 Replies

7. Shell Programming and Scripting

get rid of non-alphanumeric characters

Hi! Could anyone so kindly help me a code to eliminate from a txt file, obtained by collecting and merge several web-page, every word (string) containing non alphabetical, numeric and punctuation character (i.e NON a-zA-Z0-9, underscore and punctuation mark)? Thanks a lot for the help to... (5 Replies)
Discussion started by: mjomba
5 Replies

8. Shell Programming and Scripting

Sorting with non- and alphanumeric characters

Hi guys, I'm new to this forum and I'm not a UNIX expert. I can't figure out this certain problem i'm having: I need to sort some words, some of the words are annotations (enclosed within < and >). I need to have them sorted alphabetically with all non-alphanumeric characters up front. For... (2 Replies)
Discussion started by: fed.m.ang
2 Replies

9. Shell Programming and Scripting

alphanumeric comparision

I have a requirement where I need to check if where r1v07l09ab is a software release. I should always check for this to be true to continue the release deployment because an older release should not be deployed by mistake. I mean only the release greater than the current release should be... (3 Replies)
Discussion started by: rakeshou
3 Replies

10. Shell Programming and Scripting

sort command - alphanumeric

I have a file I'm trying to sort such as fred1 fred2 fred10 fred11 ... when I sort I get fred1 fred10 fred11 fred2 ... using sort can any give me the syntax to sort this is dict order e.g., (4 Replies)
Discussion started by: gefa
4 Replies
Login or Register to Ask a Question