@Balajesuri.. Thanks for your wonderful reply. There were some error in my file only.
But there is one more issue. The master columns on which we are performing the sorting are multiple..
I give you the example, lets suppose we have .csv file which has 4 columns
Original File
hello,code,a,check
hi,take,a,perform
tag,button,b,below
message,lap,a,hint
do,you,b,any
in,the,a,below
And we have to perform sorting based on 3rd column
So the expected output wanted
hello,code,a,check
hi,take,a,perform
message,lap,a,hint
in,the,a,below
tag,button,b,below
do,you,b,any
---------- Post updated at 01:45 PM ---------- Previous update was at 12:56 PM ----------
Hi
I tried some thing like below
use warnings;
use strict;
my (%hash, @arr, $rec);
my $p_file='sort_file.txt';
open('NEW',">$p_file") || die "Error open file $p_file\n";
open FILE, "<flat_file.csv";
while (<FILE>) {
chomp;
@arr = split /,/;
$rec++;
$hash{$arr[15].'|'.$rec} = join(',',@arr[0..14]) . '|' . join(',',@arr[16..$#arr]);
}
close FILE;
undef @arr;
for (sort keys %hash) {
@arr = split /\|/, $hash{$_};
print NEW "$arr[0],$_,$arr[1]\n";
}
close NEW;
But with this now extra record is coming..How can i remove that..