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

Replies are listed 'Best First'.
Re: one liner truncate beginning at line with keyword
by LanX (Saint) on Jan 22, 2013 at 18:23 UTC
Re: one liner truncate beginning at line with keyword
by BrowserUk (Patriarch) 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 (Abbot) 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.