Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

one liner truncate beginning at line with keyword

by simplyseth (Initiate)
on Jan 22, 2013 at 18:19 UTC ( #1014755=perlquestion: print w/ replies, xml ) Need Help??
simplyseth has asked for the wisdom of the Perl Monks concerning the following question:

I wish to do a perl one liner that truncates a file beginning at, and including, the line

#vgc config

Thanks.

Comment on one liner truncate beginning at line with keyword
Re: one liner truncate beginning at line with keyword
by LanX (Canon) on Jan 22, 2013 at 18:23 UTC
Re: one liner truncate beginning at line with keyword
by BrowserUk (Pope) on Jan 22, 2013 at 18:57 UTC

    perl -ple" exit if /#vgc config/" in > out

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: one liner truncate beginning at line with keyword
by kennethk (Monsignor) on Jan 22, 2013 at 19:00 UTC

    What did you try? What didn't work? Why do you want it to be a 1-liner? The easiest way I see to do it would be using a flag to track whether you've seen the line in question and the -n and -i switches.

    So pretty much what LanX said.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: one liner truncate beginning at line with keyword
by simplyseth (Initiate) on Jan 22, 2013 at 23:33 UTC
    perl -pi -e " exit if /#vgc config/"  /etc/rc.local

    The above works perfectly. Thank you PERL monks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1014755]
Approved by Lotus1
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2014-09-21 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls