texasweb
02-02-2002, 01:15 PM
I have a tab delimited file with a max of 25 fields.
I want to read in the file and split it into 4 files.
The 8th tab field determines what file the record goes into.
Possible values are RE LD CI MF.
Can anybody help me on this please?
dektong
02-02-2002, 01:56 PM
I wrote a code, but I did not realize until later that it was the 8th delimited tab that determines the file, I thought it was the last delimited tab. Sorry about this ...
priyadi
02-02-2002, 02:27 PM
OK, here's my take... Standard disclaimers apply :)
open(RE, ">RE");
open(LD, ">LD");
open(CI, ">CI");
open(MF, ">MF");
open(INPUT, "inputfile");
while(<INPUT>) {
chomp;
my @fields = split(/\t/);
my $field8 = $fields[7];
if ($field8 eq 'RE') {
print RE "$_\n";
} elsif ($field8 eq 'LD') {
print LD "$_\n";
} elsif ($field8 eq 'CI') {
print CI "$_\n";
} elsif ($field8 eq 'MF') {
print MF "$_\n";
}
}
texasweb
02-02-2002, 04:36 PM
Excellent.
Thanks for the fast response and the accurate code. It worked on the first try and did exactly what I wanted.