remove caret (^) symbol from pattern using sed

Hi,

I am trying to remove the caret symbol from a bash variable. This is the variable:

var="GOTAN^TOK^B"

and this is the code I am trying to use to remove the caret symbol:

nocarrot=`echo $var | sed -e 's/^/_/g'`

This is the output intended (but not acheived with the above function):

GOTAN_TOK_B

Please help. Thanks in advance.

echo "GOTAN^TOK^B" | sed 's/\^/_/g'

You just needed to escape ^, since it has special meaning in regular expressions (Start of line or not).

Use a "\" to escape its normal behavior of pointing to the start of the line/word.

nocarrot=`echo $var | sed -e 's/\^/_/g'`
1 Like

echo ${var//^/_}