Link to home
Start Free TrialLog in
Avatar of Europa MacDonald
Europa MacDonaldFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Separating rows in a list according to value of first column

I have a list of data, I have sorted it into numerical ascending order according to the first column.

I have to now read the master file and separate out into new files all of the rows that start with the same number.

Could you help me please with code to do this ?

thanks
Avatar of ozo
ozo
Flag of United States of America image

perl -ape 'open STDOUT,">>$F[0]"'  file
Avatar of Europa MacDonald

ASKER

sorry, should have asked for it in a .pl file format
#!/usr/bin/perl
use strict;
use warnings;
my $f='';
while( <> ){
    /(\d+)/ and $1 ne $f and $f=$1 , (open STDOUT,">>",$f or warn "$f $!");
    print;
}
I tried

#!/usr/bin/perl
use strict;
use warnings;
my $f='master.vim';
while( <> ){
    /(\d+)/ and $1 ne $f and $f=$1 , (open STDOUT,">>",$f or warn "$f $!");
    print;
}

thankyou

but it just hangs for a long time
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial