Reputation: 55
I am trying to retrieve value between two strings which are present multiple time in one single line.
here is what I got:
time="1441491171" <DISP>something</DISP><DISP>stuff</DISP><DISP>possible</DISP>
the order for these strings as it might change by having additional strings...
I am trying to get these values are below:
"1441491171" something stuff possible
Many thanks for you help, AL.
Upvotes: 0
Views: 57
Reputation: 14955
A different aproach selecting matches instead of deleting not wanted strings:
$ grep -oP 'time=\K"\d+"|(?<=DISP>)\w+(?=</DISP)' file
"1441491171"
something
stuff
possible
$ grep -oP 'time=\K"\d+"|(?<=DISP>)\w+(?=</DISP)' file |tr '\n' ' '
"1441491171" something stuff possible
Upvotes: 0
Reputation: 158010
You can use the following sed
command:
sed 's/time=//;s/<\/*DISP>/ /g'
These are two commands, separated by a semicolon:
s/time=//
removes the time=
prefixs/<\/*DISP>/ /g
removes the <DISP>
or </DISP>
tags by a spaceUpvotes: 2