How to combine below two grep commands

Viewed 39

How to combine below two grep commands,

echo $(pci -nd ${vendor_id1}: | grep -oc ${dev_id1})
echo $(pci -nd ${vendor_id1}: | grep -oc ${dev_id2})

so far tried below but not worked,

echo $(pci -nd ${vendor_id1}: | grep -oc ${dev_id1}|${dev_id2})
echo $(pci -nd ${vendor_id1}: | grep -oc ${dev_id1}\|${dev_id2})
1 Answers

You can use

echo $(pci -nd ${vendor_id1}: | grep -Eoc "${dev_id1}|${dev_id2}"

-E option allows the POSIX ERE syntax that supports unescaped | as an alternation operator.

Pay attention at the double quotation marks around the regex string, it allows variable expansion.

Related