Sunday, May 5, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1718  / 2 Years ago, sat, november 27, 2021, 5:50:48

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.


More From » command-line

 Answers
4

You can use grep for this. And there are several approaches, look here, for example:



  1. Use the escaped pipe symbol in the expression:


    <command that spits out text> | grep "text to find|another text to find"


  2. Use grep with the -E option:


    <command that spits out text> | grep -E "text to find|another text to find"


  3. Use grep with -e options:


    <command that spits out text> | grep -e "text to find" -e "another text to find"



[#1255] Sunday, November 28, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pheter

Total Points: 223
Total Questions: 111
Total Answers: 119

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
pheter questions
Mon, Jun 21, 21, 07:35, 3 Years ago
Tue, Jul 5, 22, 22:50, 2 Years ago
Mon, Oct 25, 21, 02:09, 3 Years ago
;