Yoda
January 4, 2012, 5:13pm
1
I have a html file with the following content:-
<font face=verdana color=#000000>108946</font>
<font face=verdana color=#000000>234346</font>
I want to format the values inside the font tag using thousand separator. I have the following command which can be used for adding thousand separator:-
cat test.html | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
But it will convert the tag property numbers (color=#000000) also to thousand separator like below:-
<font face=verdana color=#000,000>108,946</font>
<font face=verdana color=#000,000>234,346</font>
How can I modify the sed options for avoiding this?
See if this works for you:
sed -e :a -e 's/>\(.*[0-9]\)\([0-9]\{3\}\)/>\1,\2/;ta' Inp_File
Note that there is no need to use "cat".
1 Like
echo '<font face=verdana color=#000000>108946</font>' | sed 's:#\([0-9]\{3\}\)\([0-9]\{3\}\):#\1,\2:1'
Yoda
January 4, 2012, 5:39pm
4
The following command works:-
sed -e :a -e 's/>\(.*[0-9]\)\([0-9]\{3\}\)/>\1,\2/;ta' Inp_File
By the way the following command is changing the tag property, not the tag value:-
echo '<font face=verdana color=#000000>108946</font>' | sed 's:#\([0-9]\{3\}\)\([0-9]\{3\}\):#\1,\2:1'
But this one is also informative syntax. Thank you. Appreciate your help.
Oh... I misread what you wanted to change:
echo '<font face=verdana color=#00000>108946</font>' | sed 's:>\([0-9]\{3\}\)\([0-9]\{3\}\):>\1,\2:1'
1 Like