request perl "one liner" to comment out if "a,b or c"

Posted on 2011-04-25
Last Modified: 2012-05-11
I want to do an inplace edit if
Line starts with
rlogin or rsh or login

I want to comment the line out

rlogin fred
login sally
eat pizza
rsh yada

would become
#rlogin fred
#login sally
eat pizza
#rsh yada


Question by:TIMFOX123
    LVL 48

    Accepted Solution

    perl -i  -pe 's/^(rlogin|login|rsh)/#$1/' file

    Open in new window

    LVL 16

    Expert Comment


    perl -pi.bak -e 's/^(r?login|rsh)/#$1/' filename

    Open in new window


    Author Closing Comment

    this work  


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now