Re: perl one-liner issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Wed, Mar 16, 2011 at 07:56:41PM +0000, Joseph L. Casale wrote:
> I am trying to deduce the one liner for an rpm I am packaging to edit a php
> configuration file from within my spec. The line I am editing looks like:
> 
> $conf['nagios_base'] = "/nagios/cgi-bin";
> 
> What are the escape requirements Perl needs from within the shell to
> search for this?
> 
> As I have seen, the syntax is a mess, any pointers would be appreciated!

Go easy on yourself, and :
a) don't try to match the quotation marks verbatim.  Instead, match them with simply a .
b) use parenthesis to 'remember' a pattern that you don't want to have
to specify again.

E.g. to replace the path on the right-hand-side, do this:
(i replaced it with a /; you could of course replace it with whatever
you want)

perl -i -ne 's/(^\s*\$conf\[.nagios_base.] = ).\/nagios\/cgi-bin.;/$1 \"\/\";/; print;' phpConfigFileName

E.g. to delete the line outright:
perl -i -ne 'print unless /^\s*\$conf\[.nagios_base.] = .\/nagios\/cgi-bin.;/;' phpConfigFileName

Cheers,

Jon
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux