SHORT STORY ALL FIXED THANKS Sorry for horrible formatting but Perl Monks makes posting a pain (all + those tages I cant remember hidden in the site so finding how to pos +t takes 10 minutes I'll never get back each time). Thanks for taking a look. Here is what I've found. The file that con +tains the matches has loads of drives like this \\HOFIL01\CALDWELLS$ \\GEMINI1\CAMBRIDGE$ \\GEMINI1\ADMIN \\GEMINI2\CONFERENCE \\HOFIL02\PROJECT \\HOIFL02\CURRFUNC \\HOFIL01\CAPELLAC$ \\HOFIL01\CARKEEKF$ When the script hits a line like \\HOFIL02\PROJECT it breaks. If I ch +ange it to \\HOFAL02\PROJECT or \\HOFIL02\PROJECT THIS or \\HOFIL02\P +Z (but no lower letter than Z) it will work (or stop on the next \\ho +fil02\p(a-y) (but if it ended in $ it was ok?! in horror at the oddness of this I simply removed all \,$ and spaces f +rom the variables before comparing them which worked fine. How bizza +r? What would cause only lines starting in \\hofil02\p(a-z)$ to caus +e an issue? Also for a start I just removed any space from the varia +bles. Then it would stop on half the lines starting in \\hofil02\p(a +-z)???$ (eg \\hofil01\pathis$). The Dat file that these patterns where being matched against looked li +ke this. [NATIONAL OFFICE] floor=2 h:=\\moent14\username$ i:=\\aknt1\operations The dats had no space on the end of the drive entries but the matching + file did. All very odd. My Perl was always bad and now it is rust +so here is my current full script (no laughing please it works nicely +). I'll mod it up to output the changed files (and eventually to rep +lace the existing ones after some more testing). # Once more into the Perl Dear Friends Bruce Taylor :: Datacom Co +nsulting # # Search all MOE DAT files in a given directory, remove any lines fou +nd in another given file use File::Find; # Built in perl function that finds files i +n directories (find - traverse a file tree) # http://www.perldoc.com/perl5.6.1/lib/File/Find.html $feeddir = @ARGV[0]; # @ARGV is the built in perl array that is + feed to the script from the command line $feeddir =~ s/\\/\//; # If the dir is given using \ (like c:\tem +p) then subsitute all \ for /'s if ($feeddir =~ "") { system("cls"); print "\n\n\n\nNo directory specified\n\n"; print "You need to specify a driectory to search down\n"; print "EG... SearchReplace.pl c:\\TEMP\DATS\n\n\n\n\n"; die; } chdir("$feeddir"); # Change working directory to the now co +rrected directory given on the command line find(\&wanted, "$feeddir"); # use the built in find command wit +h the wanted subroutine and send it the $feeddir variable sub wanted # the wanted subrouting is used to select o +nly .dat files(further) down and set the filename { # the { is used to start a code block /\.DAT$/i or return; # Nab only DATS or go to the n +ext file $filename = $File::Find::name; # set $filename variable to +full path\name ie c:\temp\dats\datfile.dat &Details($filename); # so we have the file and then fee +d that into the Details sub/sub routine } sub Details { # the Details sub $file = shift; # Open the file containing the matches to remove open(BADSHARES, "c:/testy/Bad_Shares.txt"); @BadShares = <BADSHARES>; close BADSHARES; # Open the file/s to remove these matches from open(CURRENTDAT, "$file"); @DatLines = <CURRENTDAT>; close CURRENTDAT; # For each line of the file containing the matches to remove for ($a = 0; $a < scalar(@DatLines); $a++) { # Go through each line of the file you want to remove the matches +from for ($i = 0; $i < scalar(@BadShares); $i++) { # Remove any \, $ or space from the line being worked on from each + file (seems to upset perl in unnatural ways) $BadShares[$i] =~ s/ //g; $BadShares[$i] =~ s/\\//g; $BadShares[$i] =~ s/\$//g; $DatLines[$a] =~ s/ //g; $DatLines[$a] =~ s/\\//g; $DatLines[$a] =~ s/\$//g; next if (!($DatLines[$a] =~ m/($BadShares[$i])/i)); chomp $DatLines[$a]; chomp $BadShares[$i]; print "$file $DatLines[$a] $a $BadShares[$i] + $i\n"; } } }
In reply to Re^2: Remove lines from a list of files based on those in a given file
by Paws_of_Iron
in thread Remove lines from a list of files based on those in a given file
by Paws_of_Iron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |