regex: matching lines that don't contain a certain word

F

Frank Skare

Hello,
I have a source code file where I would like to
delete all lines that don't contain a certain word.
Is it possible to build a regex that match lines
that don't contain a certain word?

Thanks
Frank
 
A

Ala Qumsieh

Abigail said:
Frank Skare ([email protected]) wrote on MMMDCCCLXXXI September
MCMXCIII in <URL:-- Hello,
-- I have a source code file where I would like to
-- delete all lines that don't contain a certain word.
-- Is it possible to build a regex that match lines
-- that don't contain a certain word?


Yes, but why would you in this case? Just do:

perl -ni -we 'print unless /word/' source_code_file

Err, maybe the double negative is throwing me off, but shouldn't that be:

perl -ni -we 'print if /word/' source_code_file

? Or if you're using a real OS:

grep word source_code_file > new_source_code_file

--Ala
 
J

Jim Cochrane

Err, maybe the double negative is throwing me off, but shouldn't that be:

perl -ni -we 'print if /word/' source_code_file

Yes, the specs were (perhaps unintentionally) rather sneaky.

If he wants "word" exactly, he should change that to:

perl -ni -we 'print if /\bword\b/;' source_code_file
? Or if you're using a real OS:

grep word source_code_file > new_source_code_file

and, likewise, to:

grep '\<word\>' source_code_file > new_source_code_file
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top