regex - How to extract the content between two brackets by using grep? -
1:failed + *1 0 (8328832,ar,undeclared)
this expect : 8328832,ar,undeclared
i trying find general regex expression allows take content between 2 brackets out. attempt is.
grep -o '\[(.*?)\]' test.txt > output.txt
but cannot match =(
thanks
grep -op '\(\k[^\)]+' file
\k
means use look around regex advanced feature. more precisely, it's positive look-behind assertion, can :
grep -op '(?<=\()[^\)]+' file
if lack -p
option, can perl :
perl -lne '/\(\k[^\)]+/ , print $&' file
another simpler approach using awk
awk -f'[()]' '{print $2}' file
Comments
Post a Comment