开发者

How to keep only some keywords in text file

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜