开发者

How to keep only some keywords in text file

开发者 https://www.devze.com 2023-02-12 07:48 出处:网络
I have a text file with some emails inside. I need to remove all emails wit开发者_如何学Pythonhout keywords inside (ie: gmail, yahoo...).

I have a text file with some emails inside. I need to remove all emails wit开发者_如何学Pythonhout keywords inside (ie: gmail, yahoo...).

Is there a way to do this ?

Thanks in advance.


Yes. In which language do you want it?

example in Smalltalk:

((FileStream fileNamed: 'emails.txt') 
    substrings: eMailSeparatorChar) 
    reject: [:a|a includesSubString: aKeyWord]


Assuming each email is in single line

grep -wEi 'gmail|yahoo|aol' emailFile

-w for words

-i Case insensitive

emailFile is the file containing emails .

following changes the input file.

grep -wEi 'gmail|yahoo|aol' emailFile > tempFile && cp tempFile emailFile && rm tempFile

If you want to add more to the list just add '|' serviceProvide

0

精彩评论

暂无评论...
验证码 换一张
取 消