#AG1 4
Jacob Christopher Joseph Ethan
#AG2 3
Madison2 Olivia Emma
#AG3 2
Samantha Michael
Hi! all. i have the above input fie with data grouped as group name and members in that group that are seprated by a tab.
i wan to split the above data into 3 separate files (the line with hash and the immediate next line with members).
also i want to have in that file, one member per row and not in columns.
for example as
AG3.txt
Samantha
Michael
thanks in advance
her is what i have tried sofar.
#!/usr/bin/perl -w
open(FILER1, "input.txt") || die "couldn't open the file\n";
my ($file, $line, $memb, $num);
my (@members);
use strict;
use diagnostics;
while(!eof(FILER1)){
$line=<FILER1>;
if($line=~/#/){
$line=~/#(AG\d+)\s .*\n/;
$file=$1;
open FH, ">$file" or die "Failed to create file";
$line = <FILER1>;
@members = split /\t/, $line;
foreach $memb ( @members ){
print FH "$memb\n";
}
close FH;
}
}
Jacob Christopher Joseph Ethan
#AG2 3
Madison2 Olivia Emma
#AG3 2
Samantha Michael
Hi! all. i have the above input fie with data grouped as group name and members in that group that are seprated by a tab.
i wan to split the above data into 3 separate files (the line with hash and the immediate next line with members).
also i want to have in that file, one member per row and not in columns.
for example as
AG3.txt
Samantha
Michael
thanks in advance
her is what i have tried sofar.
#!/usr/bin/perl -w
open(FILER1, "input.txt") || die "couldn't open the file\n";
my ($file, $line, $memb, $num);
my (@members);
use strict;
use diagnostics;
while(!eof(FILER1)){
$line=<FILER1>;
if($line=~/#/){
$line=~/#(AG\d+)\s .*\n/;
$file=$1;
open FH, ">$file" or die "Failed to create file";
$line = <FILER1>;
@members = split /\t/, $line;
foreach $memb ( @members ){
print FH "$memb\n";
}
close FH;
}
}