08-10-2020 02:46 PM
Hello all,
I am trying to use grep to return multiple lines that may match different things (i.e. either/or). For example, say I have the following output on an APIC:
Node201
Node202
Node203
I would like to have grep return lines with EITHER "201" OR "202" in the line, so for the above output, I would like to have grep return:
Node201
Node202
I have tried using the | symbol and also regex grouping like so, but with no luck:
grep "201|202"
grep "(201|202)"
I have also tried grep -e as well as extended grep, also with no luck.
Does anyone know how I would return lines from output that matches multiple criteria in an either/or fashion?
Solved! Go to Solution.
08-10-2020 03:16 PM - edited 08-10-2020 03:21 PM
Hi @vv0bbLeS ,
try using egrep (or grep -e)
So you type
command | egrep "20[12]"
I hope this helps
Don't forget to mark answers as correct if it solves your problem. This helps others find the correct answer if they search for the same problem
08-10-2020 03:16 PM - edited 08-10-2020 03:21 PM
Hi @vv0bbLeS ,
try using egrep (or grep -e)
So you type
command | egrep "20[12]"
I hope this helps
Don't forget to mark answers as correct if it solves your problem. This helps others find the correct answer if they search for the same problem
08-11-2020 05:31 AM
Wow DUH I didn't even think about using character classes lol, that works perfectly! And i also tried it with regular grep and it also works with that. Thanks again!
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: