Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Perl search and replace

by apomatix (Novice)
on May 19, 2011 at 22:44 UTC ( [id://905827]=note: print w/replies, xml ) Need Help??


in reply to Perl search and replace

Probably you don't want to use ., since it will match anything, including a line beginning with something like "XDefault". Also, the + matches one or more, so the regex you wrote would only match if there was at least one character in front of the D. If you want to enforce that there is only whitespace at the beginning or end then use \s* instead of .+, and also anchor at both beginning and end. So your regex becomes /^\s*Defaults    (requiretty|env_reset)\s*$.

Here is a one-liner:

perl -pi -e '$_ = "#$_" if /^\s*Defaults    (requiretty|env_reset)\s*$/'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://905827]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found