perl or sed s/// problem

Kevin Brown kevin_brown at qwest.net
Thu Aug 5 18:09:15 MST 2010


>> line="password    requisite     /lib/security/$ISA/pam_cracklib.so
>> newline="password required /lib/security/$ISA/pam_cracklib.so
>> I need to maintain whitespace
>>
>> perl -p -i -e s/"$line"/"$newline"/  file
>>
>> That tosses out all kinds of errors
>
> Modern regexp engines allow you to use an arbitrary char as the pattern
> delimiter.  If I've got slashes in my patterns, I tend to use # as the
> delimiter, which allows you to avoid Leaning Toothpick Syndrome.  Other people
> may use | .  # is visually distinctive and not as common as / in some
> string-replace contexts, though:
>
> perl -p -i -e 's#"$line"#"$newline"#'  file

The | sits right under the \ on the keyboard, so it is easy to put into 
scripts. The # may seem like a reasonable delimiter unless the lines 
being read in have comments in them. In which case most files I've seen 
use the # to denote a comment or a comment line...


More information about the PLUG-discuss mailing list