Shell – How to grep multiple patterns from a pipe

grepquotingregular expressionshell

I want to find three patterns in a list. I tried typing

$ pip3 list | grep -ei foo -ei bar -ei baz

but the shell throws a broken pipe error and a large Traceback.

How do I grep for multiple patterns passed from a list that is piped to grep?

Best Answer

Try:

pip3 list | grep -Ei 'foo|bar|baz'

Here is a real life example from my Arch server:

pip3 list | grep -Ei 'ufw|set'
setuptools 40.0.0 
ufw        0.35   

OS and grep info:

uname -a
Linux archlinux 4.16.6-1-ARCH #1 SMP PREEMPT Mon Apr 30 12:30:03 UTC 2018 x86_64 GNU/Linux

grep --version
grep (GNU grep) 3.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
Related Question