开发者

grep with pattern (i.e., search for mutliple strings/searches/options) -- file type can't be specified?

I would like to do a recursive grep and search for multiple strings/options at the first time (I think this might be called pattern? not sure).

Semantically, I want so search for "foo | bar". There are various options. Among others: grep -- "foo\|bar" *.txt does the job.

I cannot use that command though since I didn't figure out how to tell it to search recursively. I.e., the '-r' attribute doesn't work. Q1: Any idea?

Anyway, I find the following option more convenient anyway:

grep -r -f patternfile * because it allows me to place my matches ("foo" and "bar"开发者_运维百科; and any other) into a file (here called patternfile), one per line. If one searches for many expressions, this is clearly more convenient and readable.

However this has its disadvantages as well! It seems like I have to specify "*" here for what is being searched. But of course I want to restrict it, for example to text files, *.txt. But that doesn't work... *Q2: How to use this command with .txt at the end? (And why doesn't it accept that in the first place?)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜