Home: Perl Programming Help: Regular Expressions:
removing an entire line



AndrewG
stranger

Oct 2, 2001, 2:29 PM


Views: 15282
removing an entire line

Hello All,

I'm trying to get regex to delete the entire line if it finds 'jpg' anywhere in the line. I'm trying to shrink down my Apache log files.

The closest thing I have come up with is s/jpg/ /

Thank you.




mhx
Enthusiast

Oct 3, 2001, 3:26 AM


Views: 15279
Re: removing an entire line

The easiest thing would be to use perl's inplace editing capability:

Code
perl -i.old -ne '/jpg/i or print' access.log

This will make a backup (named access.log.old) of access.log and remove all lines from access.log that contain 'jpg', no matter in which case.
But you can also use the good old grep instead of perl:

Code
grep -iv jpg access.log >access.log.short

Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



AndrewG
stranger

Oct 3, 2001, 9:46 AM


Views: 15278
Re: removing an entire line

Thanks again Marcus,

Another great command for my notes.