Newbie help required

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'd be really grateful if someone could show how Perl can be used to
read a text file and delete any lines of text with a key word and then
close and save the file.

For example, I want to remove all lines with "dave" in them in


2wordswordsblahblah dave wordsblahblah
4wordswordsblahblah dave wordsblahblah


would be manipulated to:




I'm a complete newbie with this stuff (I can get a script running on a
web server, etc.) and am trying to avoid having to write something from
scratch.  The intent is to run a the script to process one local file.
And that's it.

Can someone point me in the right direction of what should presumably
be a simple script that I can cut and paste?  I can't find anything
using google...because it is so simple perhaps??



Re: Newbie help required

Quoted text here. Click to load it
OK: just a few points to get them out of the way:-

1. your subject line is useless
2. this is the wrong newsgroup for general perl questions
3. you need to read the posting guidelines before you post in any

However, read on...
Quoted text here. Click to load it

You could do this with the command line.

grep -v dave inputfile.txt > outputfile.txt

With perl:

perl  -ne 'print unless /dave/' < inputfile.txt > outputfile.txt

or (for inplace edit)

perl -ibak -ne 'print unless /dave/' inputfile.txt

will edit inputfile.txt and save a backup of the original in

You need to read

man perlrun
man perlre

Note that his question is fairly basic. would be a good starting point.



Site Timeline