Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Athanasius (Chancellor)
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?
[Happy-the-monk]: Discipulus: why are you looking for a Danish monk?
[1nickt]: choroba really you did not like it hm?
[choroba]: no, just trying to judge a book in the same way
[choroba]: i.e. using it for a totally different purpose than it was written for

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2017-11-17 21:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (272 votes). Check out past polls.

    Notices?