CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



AndrewG
stranger

Oct 2, 2001, 2:29 PM

Post #1 of 3 (5194 views)
removing an entire line Can't Post

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

Post #2 of 3 (5191 views)
Re: removing an entire line [In reply to] Can't Post

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

Post #3 of 3 (5190 views)
Re: removing an entire line [In reply to] Can't Post

Thanks again Marcus,

Another great command for my notes.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives