I have some data which includes a bunch of bracketed codes, sometimes multiple on one line.
Lorem ipsum (ABC123) dolor sit amet
consectetur adipiscing elit (BCD234)
sed do (345CDE) eiusmod tempor (8675309) incididunt
All my attempts to pull out the bracketed strings (grep -P -i -o "(?<=\().*(?=\))"
and grep -E -i -o "\(CAS.*\)"
) have resulted in an output like:
ABC123
BCD234
345CDE) eiudmod tempor (8675309
whereas what I need is :
ABC123
BCD234
345CDE
8675309
How should I go about this? I'm using GNU grep.
I bonus would not be broken by unmatched brackets and pull out ABC123
from ut labore (et dolore (ABC123) magna aliqua
but that's not too important.