开发者

Selecting lines which match any word from a list with grep

Can grep pick lines if at least one element from a list of words appeared? For example

grep "hello开发者_如何学Go world" file1 

grep must give me all lines which have either the word hello or the word world or both of them.


grep "hello\|world" file1


put your patterns in some file patterns.txt, one pattern per line, and run

grep -Ff patterns.txt file1


How about

grep -r "hello\|world" file1

That's a recursive grep by the way. It searches recursively for the term "hello world" in file1. It can also apply to a directory like so:

grep -r "hello\|world" dir/dir2/


Try this,

echo "hello world "| grep -o  "\bworld\b" 

output is

world 

or

grep -E 'hello|world' filename
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜