Avatar of Europa MacDonald
Europa MacDonald
Flag 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
Perl

Avatar of undefined
Last Comment
ozo

8/22/2022 - Mon
ozo

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

ASKER
sorry, should have asked for it in a .pl file format
ozo

#!/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;
}
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Europa MacDonald

ASKER
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
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.