Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: perl one liner to search for a string, then search for a different string and append a new line

by Athanasius (Monsignor)
on Dec 20, 2012 at 13:37 UTC ( #1009744=note: print w/ replies, xml ) Need Help??


in reply to Re: perl one liner to search for a string, then search for a different string and append a new line
in thread perl one liner to search for a string, then search for a different string and append a new line

You need to put capturing parentheses around the text to be matched, in order to initialise $1.

You should also definitely follow uncoolbob’s advice and use a non-greedy quantifier.

And your code will be much easier to read if you use different delimiters, because then you won’t have to backslash all the forward slashes (“leaning toothpick syndrome”):

perl -0777 -elnp 's{(<Directory "/usr/local/awstats.+?</Directory>}{$1 +\nCustomLog /usr/local/awstats/logs/access_log comdinedio}s' httpd.co +nf

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re^2: perl one liner to search for a string, then search for a different string and append a new line
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009744]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-08-21 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls