File: //ibin/removeme
#!/usr/bin/perl
# sed -i '/comodoca.com/d' *.db
# RemoveMe Function Opens Files and removes lines with matching strings
if((!$ARGV[0])||(!$ARGV[1])) {
print "usage: remove_me <filename> <'string to search for'>\n";
} else {
$found = "N";
$i=0;
open(TEMP,">$ARGV[0].temp") || die "Can't create $ARGV[0] temp file $!\n";
open(OLD,"$ARGV[0]") || die "Can't open $ARGV[0] $!\n";
print "\033[1;31m\n----------------------------------------------------------------------\033[0m\n";
print "\033[1;31m:Removing: \033[1;33m".$ARGV[1]. " from " . $ARGV[0];
print "\033[1;31m\n_____________________________________________________________________________\033[0m\n";
#print "\n------------------------------------------------------------\n";
#print "-- Removing ".$ARGV[1]. " from " . $ARGV[0] . "\n";
#print "\------------------------------------------------------------\n";
# Debug Parameters
#print "$ARGV[0] --- $ARGV[1] --- $ARGV[2]";
#exit;
while($line=<OLD>) {
chomp($line);
# Find 'string' in $line, if it's there skip writing the line or 'next' line.
if($line =~ /$ARGV[1]/i) {
if ($ARGV[2]) {
print $line . " Removed\n";
}
$found = "Y";
$i++;
next; }
print TEMP "$line\n";
}
close(OLD);
close(TEMP);
# -< Backup Option >- Comment out the next line if you don't want a backup file to be made.
#print `mv $ARGV[0] $ARGV[0].bak`;
# Move the Temp file to the original file
print `mv $ARGV[0].temp $ARGV[0]`;
if ($found eq "Y") {
print "\n$i Changes made to $ARGV[0].\n\n";
exit;
}
print "\nNo Changes made to $ARGV[0].\n\n";
exit;
}
exit;