I understand how to use grep in the simple form:
<command that spits out text> | grep "text to find"I would like to be able to grep multiple different bits of text all at once.
How do I do that? Is grep the correct command to do this?
Example
I run arp-scan and I get a list of devices and their mac addresses. I want to search for the presence of multiple unique mac address strings. If I only wanted 1 mac address, I would use grep like this:
arp-scan --localnet --interface=<my interface> | grep "mac address"I have heard of sed, but I don't know if it fits my use case.
2 Answers
You can use grep for this. And there are several approaches, look here, for example:
Use the escaped pipe symbol in the expression:
<command that spits out text> | grep "text to find\|another text to find"Use
grepwith the-Eoption:<command that spits out text> | grep -E "text to find|another text to find"Use
grepwith-eoptions:<command that spits out text> | grep -e "text to find" -e "another text to find"
There are several ways to do this
pass multiple patterns with
-eex.somecommand | grep -e foo -e bar -e bazuse a regular expression that matches multiple patterns ex. using the extended regular expression alternation operator
|somecommand | grep -E 'foo|bar|baz'put the patterns one-per-line in a file, and pass the file to
grepvia the-foption ex.somecommand | grep -f patfilewhere
$ cat patfile foo bar baz