Hi List I have completed the code successfully. Please find the code below.
#!/usr/bin/perl use strict; use warnings; my $file_name = "RXMOI_TRX_CMD"; open my $RFH, '<', $file_name; my $sequence_no; my %file_content_hash; while (my $line = <$RFH>) { chomp($line); if ($line =~ m/.*?\-(\d+)\-(\d+).*/) { $sequence_no = "$1$2"; # print "$sequence_no-- $line\n"; $file_content_hash{$sequence_no}="$line"; } } for my $key ( sort {$a<=>$b} keys %file_content_hash) { print "($key)->($file_content_hash{$key})\n"; } Please let me know if there is more good ways (performance wise since I have to do this operation on lot of files) to complete the task. [?] I am sure there are lots of good ways to complete this task. Best Regards Anirban. On Tue, Mar 24, 2015 at 4:12 PM, Anirban Adhikary < anirban.adhik...@gmail.com> wrote: > Hi List > I have a file like this. > RXMOI:MO=RXOTRX-*473-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&&186,TEI=0; > RXMOI:MO=RXOTRX-*473-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&&231,TEI=5; > RXMOI:MO=RXOTRX-*473-1*,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&&195,TEI=1; > RXMOI:MO=RXOTRX-*473-9*,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&&267,TEI=9; > RXMOI:MO=RXOTRX-*473-4,*SC=0,DCP1=214,SIG=SCCONC,DCP2=215&&222,TEI=4; > RXMOI:MO=RXOTRX-*1-8*,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&&258,TEI=8; > RXMOI:MO=RXOTRX-*1-2,*SC=0,DCP1=196,SIG=SCCONC,DCP2=197&&204,TEI=2; > RXMOI:MO=RXOTRX-*1-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&&186,TEI=0; > RXMOI:MO=RXOTRX-*1-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&&231,TEI=5; > RXMOI:MO=RXOTRX-*1-1,*SC=0,DCP1=187,SIG=SCCONC,DCP2=188&&195,TEI=1; > RXMOI:MO=RXOTRX-*1-4,*SC=0,DCP1=214,SIG=SCCONC,DCP2=215&&222,TEI=4; > RXMOI:MO=RXOTRX-*460-9*,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&&267,TEI=9; > RXMOI:MO=RXOTRX-*460-4*,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&&222,TEI=4; > RXMOI:MO=RXOTRX-*460-8*,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&&258,TEI=8; > RXMOI:MO=RXOTRX-*460-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&&231,TEI=5; > RXMOI:MO=RXOTRX-*460-1*,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&&195,TEI=1; > RXMOI:MO=RXOTRX-*460-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&&186,TEI=0; > > This file is from a testing environment. But in production environment > this file can be more than 500 lines. So my goal is to sort the file based > on the bold numbers and create a new file. > This is required for data validation. If the file is not in sorted order > then it will be very difficult to validate the file manually. > > For this I have started with the following code > > #!/usr/bin/perl > use strict; > use warnings; > my $file_name = "RXMOI_TRX_CMD"; > open my $RFH, '<', $file_name; > my $sequence_no; > my $lowest_no; > while (my $line = <$RFH>) { > chomp($line); > if ($line =~ m/.*?\-(\d+)\-(\d+).*/) { > $sequence_no = "$1$2"; > print "$sequence_no\n"; > } > } > > I can extract the number into a variable but after that not getting any > idea how to proceed. Could you please provide some logic so that I can > proceed further. > > Best Regards > Anirban. > > >