I would like to know if there is a way to combine a series of grep statements where the effect is to "and" the expressions rather than "or" the matching expressions.
Demo below:
./script
From one grep statement, I want output like this
a b c
not like this
a
c
a b
a b c
a b c d
Hear is a look at the script.
#!/bin/bash
string="a
b
c
d
a b
a b c
a b c d"
echo -e " From one grep statement I want output like this"
echo "$string" |
grep a |grep c |grep -v d #Correct output but pipes three grep statements
echo -e "
Not like this"
echo "$string" |
grep -e'a' -e'c' -e-v'd' #One grep statement but matching expressions are "or" versus "and"