开发者

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

开发者 https://www.devze.com 2022-12-07 21:38 出处:网络
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).

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

精彩评论

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