Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

editing a file to remove a field or string - help

Status
Not open for further replies.
Apr 2, 2002
25
US
I have a huge log that is created when a system audit is ran on a Solaris 8 Box.

I want to remove all the lines in the file that contain the pattern /var/sadm/*

Any ideas ? I have tried with no luck.

Thanks
 
Ok.

$file = shift || die "specify log file name on cmd line\n";
$old_file = "$file.old";

rename $file, $old_file;

open(OLD_FILE, $old_file) || die $!;
open(NEW_FILE, ">$file") || die $!;
while(<OLD_FILE>){
print NEW_FILE unless m#/var/sadm/#;
}
close(OLD_FILE);
close(NEW_FILE);
Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Thanks Mike,

I'm getting some errors from that code about = and die not found.

I'll keep checking to see if I can figure it out.


P.S. I knew I should ahve taken that class on Perl instead of C/C++ [sadeyes]
 
faq219-969 can be adapted to:
[tt]
perl -i -n -e 'print unless m</var/sadm/>' file
[/tt]
Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top