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?

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

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

perl -F'\|' -ane'
  @F > 6 and $_{$k = $F[3]} = $_ or
  $_{$k} .= $_;
  print map $_{$_}, sort keys %_ if eof
  ' infile

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

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.

Yes i have tried the command and its working

Well,
if you know Perl and there is part of the code that you don't understand,
I'll try to explain it.
Otherwise, you may search this site for Perl tutorial.

i have no idea in pearl, anyways I'll learn it and get back to you if i am not able any part of the command .
I have another doubt
in the above command we are sorting the input file with one column (column 4) .how can i sort the input file (varchar sort) with two columns
For eg: in the input file first i need to sort with column 3 and then with column 4

thanks in advance

perl -F'\|' -ane'
  @F > 6 and $_{$k = join "\|", @F[2,3]} = $_ or
  $_{$k} .= $_;
  print map $_{$_}, sort keys %_ if eof
  ' infile