Issue
I have a text log file that I need to add some basic html like stuff (to match decades of older logs).
It basically looks like this in all lines
<constant> <various> text
and should transform to this in each line
<font color="#7a40b0">constant:</font><font color="#0000fc">various:</font> text
constant
always remains the same, various
changes (these are usernames, could be anything, e.g. F0oBar 1)
I tried
sed 's|'\<constant\>\ \<'.*'\>'|'\<font\ color\=\"#7a40b0\"\>constant:\</font\>\<font\ color\=\"#0000fc\"\>\1:\</font\>'|g'
but this just returns
<font color="#7a40b0">constant:</font><font color="#0000fc">1:</font>
I tried searching on how to make the back reference work but I'm sure now I'm messing up the wildcard. As soon as I use parenthesis, brackets and/or ^ stuff breaks (the regex doesn't match anymore). I've used https://sed.js.org to give me a visual help so I hope this gave me correct feedback.
Solution
Using sed
$ sed -E 's|<([^ ]*)> <([^ ]*)>|<font color="#7a40b0">\1:</font><font color="#0000fc">\2:</font>|' input_file
<font color="#7a40b0">constant:</font><font color="#0000fc">various:</font> text
Answered By - HatLess Answer Checked By - Senaida (WPSolving Volunteer)