Unusual output of sed

i have a sed command that is looking for the workds OK, WARNING and CRITICAL and add html color to those words. e.g:

echo $CONSUMABLE |$SED s/OK./\<span\ style\=\"background-color\:green\;font-weight\:bold\;\"\>OK\<\\\/span\>/g

the output breaks every so often and changes my output as following:

<span style="backg" round-color:green;font-weight:bold;="">OK</span>

i cannot find what is causing this strange behavior or how to fix this.

can anyone help me understand what i am doing wrong?

Looks like your quoting is a bit crazy. This works and is easier to read:

echo "$consumable" | sed 's#OK.#<span style="background-color:green;font-weight:bold;">OK</span>#g'
echo "$consumable" | sed '
s#OK#<span style="background-color:green;font-weight:bold;">OK</span>#g
s#WARNING#<span style="background-color:orange;font-weight:bold;">WARNING</span>#g
s#CRITICAL#<span style="background-color:red;font-weight:bold;">CRITICAL</span>#g
'

i am still getting some unexpected results:

<span style="backgr
 ound-color:green;font-weight:bold;">OK</span>
<span style="background-color:green;font-weight:bold;">OK</spa>

i cannot understand what they have in common or why my results give me weird printing but only on one or 2 lines...

Please show us exactly what you are running, word for word, letter for letter, keystroke for keystroke. Also show all relevant input.

CONSUMABLE="`$SNMPCHECKCMD -H ${PRINTERS[$PRINTER]} -C public -x \"CONSUM ALL\" -w 15 -c 10 |$SED  s/\!/\ \<br\>/g |$SED s/\|.*//g`"
CONSUMABLE="`echo $CONSUMABLE |$SED '
s#OK.#<span style="background-color:green;font-weight:bold;">OK</span>#g
s#WARNING.#<span style="background-color:orange;font-weight:bold;">WARNING</span>#g
s#CRITICAL.#<span style="background-color:red;font-weight:bold;">CRITICAL</span>#g'`"
OUTPUT+=$CONSUMABLE

What does the value of CONSUMABLE end up being after this line?

CONSUMABLE="`$SNMPCHECKCMD -H ${PRINTERS[$PRINTER]} -C public -x \"CONSUM ALL\" -w 15 -c 10 |$SED  s/\!/\ \<br\>/g |$SED s/\|.*//g`"

Also, what is the value of SED?

i found the issue, but not the solution.
when i output to a file, all is fine with no issue.
the issue is with the mail command, it changes the output for some reason:
echo $OUTPUT |mail -s "Printer Summery" email@exapmle.com -a "Content-type: text/html"

i tried with send mail as well, same results. will look for alternatives.

You aren't quoting $OUTPUT, causing the shell to flatten it(convert all linefeeds into spaces, etc). Try echo "$OUTPUT"

Otherwise, you'll need to tell us how, exactly, it's "not working", and tell us in more detail than you've been telling us before. If you'd mentioned email at all before, I could have warned you how Microsoft Outlook tends to ignore all formatting and impose its own unless you enclose all text in one big <PRE> ... </PRE> block.

found the solution using mutt:
mutt -e 'set content_type=text/html' -s 'subject' 'email@example.com' </tmp/output.html

That avoids the flattening problem by not using echo $OUTPUT at all.

I suspect sendmail, etc would work fine reading from a temp file too.