I have the following text:
aaa rr tt zz pp
aaa pp xx yy uu zz
And need to extract all 'aaa', 'zz' and 'xx' pattern and print them on one line like this:
aaa zz
aaa xx zz
Best I found is grep -oP 'aaa|xx|zz'
but this return each pattern found on a new line:
aaa
zz
aaa
xx
zz
I tried to add something like tr -d '\n'
but in that case it returns the whole matches on single line which is not what I want.
NB: I need a solution which support regexp with non-greedy regexp as the search patterns would looks like: ^.+?,|,IN:.+?\-|,OUT:.+?-|State.+?[$,]