Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

84%
+9 −0
Q&A grep AND search for multiple words in files

Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regex that spans lines, but I find this annoying because of all the flags you have to set. Grep ...

posted 1y ago by matthewsnyder‭  ·  edited 1y ago by matthewsnyder‭

Answer
#4: Post edited by user avatar matthewsnyder‭ · 2023-06-12T01:31:43Z (over 1 year ago)
  • Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regex that spans lines, but I find this annoying because of all the flags you have to set.
  • Grep has a switch for printing the filenames instead of matching lines. You can put each in a file. Once you have both files, you can use `comm` to do the union.
  • ```
  • grep -r . -e 'foo' > foo.txt
  • grep -r . -e 'bar' > bar.txt
  • comm foo.txt bar.txt -12
  • ```
  • If you don't want the temp files, you can use the command inline: https://software.codidact.com/posts/288326 However, I simply put the files in `/tmp/` where they get automatically wiped at next system shutdown.
  • Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regex that spans lines, but I find this annoying because of all the flags you have to set.
  • Grep has a switch for printing the filenames instead of matching lines. You can put each in a file. Once you have both files, you can use `comm` to do the union.
  • ```
  • grep -r . -e 'foo' > foo.txt
  • grep -r . -e 'bar' > bar.txt
  • comm foo.txt bar.txt -12
  • ```
  • If you don't want the temp files, you can use the command inline: https://linux.codidact.com/posts/288328/288329#answer-288329 However, I simply put the files in `/tmp/` where they get automatically wiped at next system shutdown.
#3: Post edited by user avatar matthewsnyder‭ · 2023-06-12T01:29:29Z (over 1 year ago)
  • Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regex that spans lines, but I find this annoying because of all the flags you have to set.
  • Grep has a switch for printing the filenames instead of matching lines. You can put each in a file. Once you have both files, you can use `comm` to do the union.
  • ```
  • grep -r . -e 'foo' > foo.txt
  • grep -r . -e 'bar' > bar.txt
  • comm foo.txt bar.txt -12
  • ```
  • Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regex that spans lines, but I find this annoying because of all the flags you have to set.
  • Grep has a switch for printing the filenames instead of matching lines. You can put each in a file. Once you have both files, you can use `comm` to do the union.
  • ```
  • grep -r . -e 'foo' > foo.txt
  • grep -r . -e 'bar' > bar.txt
  • comm foo.txt bar.txt -12
  • ```
  • If you don't want the temp files, you can use the command inline: https://software.codidact.com/posts/288326 However, I simply put the files in `/tmp/` where they get automatically wiped at next system shutdown.
#2: Post edited by user avatar matthewsnyder‭ · 2023-06-09T13:30:59Z (over 1 year ago)
  • Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regexes that spans lines, but I find this annoying because of all the flags you have to set.
  • Grep has a switch for printing the filenames instead of matching lines. You can put each in a file. Once you have both files, you can use `comm` to do the union.
  • ```
  • grep -r . -e 'foo' > foo.txt
  • grep -r . -e 'bar' > bar.txt
  • comm foo.txt bar.txt -12
  • ```
  • Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regex that spans lines, but I find this annoying because of all the flags you have to set.
  • Grep has a switch for printing the filenames instead of matching lines. You can put each in a file. Once you have both files, you can use `comm` to do the union.
  • ```
  • grep -r . -e 'foo' > foo.txt
  • grep -r . -e 'bar' > bar.txt
  • comm foo.txt bar.txt -12
  • ```
#1: Initial revision by user avatar matthewsnyder‭ · 2023-06-09T11:31:23Z (over 1 year ago)
Between-lines relations are not easy to look for with grep, which is a line filter. You could use a regexes that spans lines, but I find this annoying because of all the flags you have to set.

Grep has a switch for printing the filenames instead of matching lines. You can put each in a file. Once you have both files, you can use `comm` to do the union.

```
grep -r . -e 'foo' > foo.txt
grep -r . -e 'bar' > bar.txt
comm foo.txt bar.txt -12
```