File: //ibin/removeme_silent
#!/usr/bin/perl
# 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";
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;