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

still using ,

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 -lne '/\(\k[^\)]+/ , print $&' file 

another simpler approach using

awk -f'[()]' '{print $2}' file 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -