bash - How to handle parenthesis in grep? -
bash - How to handle parenthesis in grep? -
str of next pattern:
1 abc (1 <something>) for example:
1 abc (1 hello) 1 abc (1 shalom) 1 abc (1 hola) how extract <something> str using egrep?
if want extract <something> i'd suggest grep -p (perl regex):
grep -p -o '(?<=\(1 ).*?(?=\))' inputfile the -o returns matched portion beingness <something>. regex looks text preceded (1 , followed ).
you wouldn't able egrep doesn't back upwards lookarounds. best you'd extract (1 <something>) with:
egrep -o '\(1 (.*)\)' inputfile [foo@bar ~]$ grep -p -o '(?<=\(1 ).*?(?=\))' inputfile hello shalom hola [foo@bar ~]$ egrep -o '\(1 (.*)\)' inputfile (1 hello) (1 shalom) (1 hola) bash grep
Comments
Post a Comment