I have a line that I need to parse through and extract a pattern that occurs multiple times in it.
Example line:
getInfoCall: [ call=1 origin=AAAA ] info received please proceed, getInfoCall: [ call=3 origin=BBBB ] info received please proceed, getInfoCall: [ call=5 origin=CCCC ] info received please proceed, getInfoCall: [ call=2 origin=DDDD ] info received please proceed, getInfoCall: [ call=4 origin=EEEE ] info received please proceed
And I need to pull only the "call=1 origin=EEEE" patterns from this line. Like
Just realized, the [^]] include the trailing spaces; the following * does not delete them.
And how to get rid of the blank line?
Well, either remove the embedded \n at the end of the line buffer
sed 's/[^[]*\[ *\([^]]*\)\][^[]*/\1\
/g; s/\n$//' file
Or, move the newline before the match, and remove the first embedded \n
sed 's/[^[]*\[ *\([^]]*\)\][^[]*/\
\1/g; s/\n//' file