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, |
|
|---|