I need to modify this code to eliminate any duplicate 'words' it picks up from a flat file
THE CODE
#!/usr/bin/perl -w
open(IN, "< scdreader.txt" or die "Cannot open file for read\n";
open(OUT, "> scdreaderout.txt" or die "Cannot open file for write\n";
my ($scdsrv, $scdname, $scdon, $scdjob);
while(<IN>) {
chomp;
if (m/(SCHEDULE) (.*)#(.*)$/) {
$scdsrv=$2, $scdname=$3;
}elsif (m/(ON) (.*)$/) {
$scdon=$2;
if ($scdon!~/(REQUEST)$/) {
$scdon="ACTIVE"
}
}elsif (m/([A-Z]{3}[0-9]{3}[A-Z]{2})/gi) {
$scdjob=$1;
print OUT "$scdjob\|$scdsrv\|$scdname\|$scdon\n";
}elsif (m/(END)$/) {
$scdsrv="",$scdname="",$scdon="",$scdjob="";
}
}
Close (IN);
Close (OUT);
SAMPLE IN (flat .txt file)
SCHEDULE RSWS555A#BLUMERGE
ON MO, TU, WE, TH
:
POP555BT
III777CT
POP555BT
END
*more stuff
SCHEDULE RCCS919A#WHTMERGE
ON REQUEST
:
EXCEPT UDE888QT
RXX818WT
END
*even more stuff
SAMPLE OUT (flat .xls file)
POP555BT|RSWS555A|BLUMERGE |ACTIVE
POP555BT|RSWS555A|BLUMERGE |ACTIVE <--redudant
III777CT|RSWS555A|BLUMERGE |ACTIVE
UDE888QT|RCCS919A|WHTMERGE|REQUEST
RXX818WT|RCCS919A|WHTMERGE|REQUEST
Can someone help me figure this out? I think @rrays might be needed here.
THE CODE
#!/usr/bin/perl -w
open(IN, "< scdreader.txt" or die "Cannot open file for read\n";
open(OUT, "> scdreaderout.txt" or die "Cannot open file for write\n";
my ($scdsrv, $scdname, $scdon, $scdjob);
while(<IN>) {
chomp;
if (m/(SCHEDULE) (.*)#(.*)$/) {
$scdsrv=$2, $scdname=$3;
}elsif (m/(ON) (.*)$/) {
$scdon=$2;
if ($scdon!~/(REQUEST)$/) {
$scdon="ACTIVE"
}
}elsif (m/([A-Z]{3}[0-9]{3}[A-Z]{2})/gi) {
$scdjob=$1;
print OUT "$scdjob\|$scdsrv\|$scdname\|$scdon\n";
}elsif (m/(END)$/) {
$scdsrv="",$scdname="",$scdon="",$scdjob="";
}
}
Close (IN);
Close (OUT);
SAMPLE IN (flat .txt file)
SCHEDULE RSWS555A#BLUMERGE
ON MO, TU, WE, TH
:
POP555BT
III777CT
POP555BT
END
*more stuff
SCHEDULE RCCS919A#WHTMERGE
ON REQUEST
:
EXCEPT UDE888QT
RXX818WT
END
*even more stuff
SAMPLE OUT (flat .xls file)
POP555BT|RSWS555A|BLUMERGE |ACTIVE
POP555BT|RSWS555A|BLUMERGE |ACTIVE <--redudant
III777CT|RSWS555A|BLUMERGE |ACTIVE
UDE888QT|RCCS919A|WHTMERGE|REQUEST
RXX818WT|RCCS919A|WHTMERGE|REQUEST
Can someone help me figure this out? I think @rrays might be needed here.