perl or sed s/// problem

Jason Holtzapple ml at bitflip.net
Thu Aug 5 11:07:56 MST 2010


On 08/05/2010 10:44 AM, David wrote:
> 
> I'm having a problem with perl *and* sed with a particular replace line.  The lines I'm trying to search for, and replace, both have "/" characters, which is completely killing me.   
> 
> line="password    requisite     /lib/security/$ISA/pam_cracklib.so retry=3"
> newline="password required /lib/security/$ISA/pam_cracklib.so minlen=8 dcredit=-1 ucredit=-1 lcredit=0 minclass=3  retry=3"
> 
> I need to maintain whitespace, too.
> 
> perl -p -i -e s/"$line"/"$newline"/  file
> 
> That tosses out all kinds of errors, since perl believes the first "/lib" line to be the next delimiter.  Even using the magical \Q and \E things doesn't work.  AARRGGHH!!!   
> 
> Sed seems to have the same problem.   Anyone have any ideas on how I can get this to work?  And yes, unfortunately, I need to use the variables.

Try something like

$ sed -e "s|$line|$newline|" file

You probably also want to define your variables like line='password ...'
so that the shell preserves the literal value of $.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 554 bytes
Desc: OpenPGP digital signature
URL: <http://lists.PLUG.phoenix.az.us/pipermail/plug-discuss/attachments/20100805/09ba8ae0/attachment.pgp>


More information about the PLUG-discuss mailing list