I have text like this:
blah, blah <foo:ImportantText> blah blah time=1.234 blah blah
blah, blah <foo:AlsoImportant> blah blah blah time=9.9 blah blah
blah, blah <foo:ImportantText> blah blah time=0.987 blah blah
I want to get:
<foo:ImportantText>=1.234
<foo:AlsoImportant>=9.9
<foo:ImportantText>=0.987
I use this line:
grep -Po '(<foo:.+>).+time=(\d+.\d+)' logfile.txt
- Note I don't need to worry about false positives as
<foo:andtime=do not appear elsewhere in the text. Alsoblah blahis random text, not a literal.
This gives me:
<foo:ImportantText> blah blah time=1.234
<foo:AlsoImportant> blah blah blah time=9.9
<foo:ImportantText> blah blah time=0.987
How do I drop the intermediate text? I thought '(<foo:.+>)(?=.+time)=(\d+.\d+)' might work, but it doesn't.
Update:
grep -Po '(<foo:.+>).+time=(\d+.\d+)' logfile.txt
| awk -F ' ' '{print $1substr($NF,4)}'
This works, but is there a grep-only solution?