Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to remove a whole line if matches a keyword in a file.

by Rahul2772 (Initiate)
on Aug 22, 2016 at 10:08 UTC ( [id://1170154]=perlquestion: print w/replies, xml ) Need Help??

Rahul2772 has asked for the wisdom of the Perl Monks concerning the following question:

I want to remove a line in the file if it matches with a "Keyword" through a script.
Script is taking an input file and writing in modified output file i need to add a snippet of code so that if a keyword match it will skip that line and jump to further line.

Replies are listed 'Best First'.
Re: How to remove a whole line if matches a keyword in a file.
by QuillMeantTen (Friar) on Aug 22, 2016 at 10:42 UTC

    Greetings,
    First thing first, have you tried anything? Do you have any running code that copy one file into another line by line?

    The following snippet could do the trick, BUT you should understand what each line does:

Re: How to remove a whole line if matches a keyword in a file.
by Laurent_R (Canon) on Aug 22, 2016 at 12:58 UTC
    You might want to try this one-liner:
    $ echo 'foo > bar > foobar > baz > foobar' | perl -ne 'print unless /^bar/;' foo foobar baz foobar
    The output might be redirected to a file if needed.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found