How to add cubed special character in Bash SED command

Viewed 42

I am using the sed command below to add characters to a list of numbers. In this case I'm trying to add gcm³.

sed -ie 's/^//;s/$/ gcm3/' numbers.txt

But rather than gcm3 I would like I would like to appear as gcm³. How can I get the proper cubed within sed?

1 Answers

You may use extended characters in sed replacement as is.

You may use

sed 's/^//;s/$/ gcm³/' file > outfile
sed -i 's/^//;s/$/ gcm³/' file

See online sed demo:

s='23'
sed 's/^//;s/$/ gcm³/' <<< "$s"
# => 23 gcm³
Related