sed REGEX to print multiple occurrences of a pattern from a line

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

call=1 origin=AAAA
call=2 origin=DDDD
call=3 origin=BBBB
call=4 origin=EEEE
call=5 origin=CCCC

I know we can do it with awk easily. But trying to know if there is a way we can try with SED regex.

Tried below and got only the last part of it.

echo "above string" | sed -e 's/.*\(call=[0-9]\) \(origin=[A-Z]\{4\}\).*/\1 \2/g'

call=4 origin=EEEE

Please help. :slight_smile:

Hello Vidyaprakash,

Following awk solution, may help you in same.

 awk '($0 == "call=4 origin=EEEE")'  Input_file
 

Thanks,
R. Singh

Try

sed 's/^[^c]*\(call\)/\1/;s/ \(call\)/\n\1/g;s/\(origin=[^ ]*\)[^\n]*/\1/g' file
call=1 origin=AAAA
call=3 origin=BBBB
call=5 origin=CCCC
call=2 origin=DDDD
call=4 origin=EEEE
sed 's#^[^[][^[]*\[##g;s#][^[]*##g' myFile | tr '[' '\n'

The following needs two lines

sed 's/[^[]*\[ *\([^]]*\) *\][^[]*/\1\
/g' file

GNU sed can take \n here

sed 's/[^[]*\[ *\([^]]*\) *\][^[]*/\1\n/g' file

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