Grep with multiple parameters

2

I need to select the rows of a file that contains the characters | or \

diff -y ontem.csv hoje.csv | grep -e "|" -e "\"

How to tell pro grep to return the rows it contains either a | or a \ ?

    
asked by anonymous 05.07.2018 / 19:49

3 answers

3

You can use the [] delimiters, which get all the characters inside them (the \ must be escaped, so it gets \ ):

grep -e "[\|]" 

See examples of this regex here .

As reported in the comments, grep also works without the -e option and does not need to escape the bar:

grep "[\|]" 
    
05.07.2018 / 19:56
5

You can use the regular expression [\|] , see:

grep:

$ diff -y ontem.csv hoje.csv | grep '[\|]'

egrep:

$ diff -y ontem.csv hoje.csv | egrep '[\|]'

awk:

$ diff -y ontem.csv hoje.csv | awk '/[\|]/{print}'

perl:

$ diff -y ontem.csv hoje.csv | perl -nle 'print if m{[\|]}'

sed:

$ diff -y novas.csv entrada.txt | sed -n '/[\|]/p'
    
05.07.2018 / 20:25
3

Follows:

diff -y ontem.csv hoje.csv | grep "[|\]"

See more at & > link

You can also use egrep - > link

    
05.07.2018 / 19:58