I am trying to use sed command to delete the copyright characters.But it is not working. Below is the command which am using.

sed 's/; © E/; (c)/g' input.txt > output.txt

but when am using vi editor to open the file it is showing \251.

Could you please help me out.

  • 2
    This could be a matter of encoding. Which character set is the input file saved in? Try the encguess command if that's available on your system. Or provide an example for download.
    – Murphy
    Feb 18 '20 at 21:35

Thanks everyone.

I got the solution as in perl :

perl -lape 's/[^[:print:]]*//g'

You can use a nasty trick to do the job using hex codes. For example in default UTF-8 ascii you can print ' with \x27 which is the hex code of single quotes.

echo -e "\x27hello\x27"

The copyright symbol is not part of default ascii table but belongs on the extended ascii codes. You can also print extended ascii as a combination of hex codes

(as advised by http://www.fileformat.info/info/unicode/char/a9/index.htm)

echo -e '\xc2\xa9'

Similarilly , you can use those hex codes in sed

a="hello ©"
sed 's/\xc2\xa9/??/' <<<"$a"  ##replacing copyright symbol with two questionmarks
hello ??

If \xc2\xa9 which stands for copyright symbol are not working, you can try \xe2\x92\xb8 which is the "CIRCLED LATIN CAPITAL LETTER C".

Also try \o251 (use a lowercase letter 'o', not a zero).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.