Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by Athanasius (Abbot)
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 studying the Monastery: (12)
As of 2015-07-02 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (41 votes), past polls