Hi guys!
Hope you masters can help with your wisdom.
What I have is the following..
==========================
=A text file called sorty.txt
SS0594Nxxxx
SS0594Nxxxx
SS0594Nxxxx
SS2834Nxxxx
SS2834Nxxxx
ST7523Nxxxx
ST7523Nxxxx
ST7523Nxxxx
ST7523Nxxxx
etc etc
--------------------------
---- The above is just a snippet.
In the above are entries for computer names.
What I want to do with this text file is the following....
- Find UNIQUE entries and pump to a new file (eg.unique.txt).
- The script would read the sorty.txt file, and find unique entries starting from the 0 position, and length 6 characters.
- For example, if there were 4 lines starting with "SS0594" in sorty.txt, then the script would find and write to a new file the line "SS0594".
- Only 1 entry in the new file for SS0594, not four. Then, if there were 2 lines starting with "SS2887" in sorty.txt, the script would find and write to a new file the line "SS2887", and so on and so on.
sorty.txt unique.txt
SS0594Nxxxx SS0594
SS0594Nxxxx SS2834
SS0594Nxxxx ST7523
SS2834Nxxxx
SS2834Nxxxx
ST7523Nxxxx
ST7523Nxxxx
ST7523Nxxxx
ST7523Nxxxx
==========================
==========
========= So far I have the following:
open (FINDUNIQUE, "< sorty.txt") or die "can't open sorty.txt: $!";
$a = 0;
while( <FINDUNIQUE> ) {
$Sys = $_;
chomp ($Sys);
@System[$a] = $Sys;
#print "a = $a - system = $System[$a]\n";
$a++
}
foreach $line (@System) {
$six = substr($line,0,6);
print "$line\n";
foreach $line1 (@System) {
$newsix = substr ($line1, 0,6);
if ($six == $newsix) {
shift (@System);
}
}
}
==========================
==========
==========
========
Any help greatly appreciated.
Somehow I have to (I think):
a) Turn the sorty.txt file into an array (slurp or something?)
b) Go through each line aind the first 6 characters of a line
c) If there are multiple lines with the same first 6 characters, then only use one unique.
I think I might have to use shift or something to move these entries from the array, along with a next function.
Thanks guys.
Start Free Trial