I want to search for multiple strings by combining grep and xargs.

Asked 2 years ago, Updated 2 years ago, 48 views

Please tell me the commands to do what you want to do below.

$ls
log1
log2
log3

$catword.txt
Apple google
facebook

$catword.txt | xargs grep-nr.
This won't work!

You want to search log1-3 in the current directory for lines that contain at least one of the strings Apple, Google, or Facebook.Finding, grep, and xargs combinations of find, grep, and xargs can be used to search for specific words across multiple files, but I couldn't find out what I wanted to do.

Thank you for your cooperation.

linux

2022-09-30 11:55

1 Answers

For Linux, I think it's GNU grep, so use the -f option.

$grep-word.txt log {1..3}

(metropolis's Comments


2022-09-30 11:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.