“Illegal Byte sequence” error while using shell co

2019-04-09 10:57发布

Getting "illegal byte sequence" error while trying to extract non English characters from a large file in MacOS bash shell. This is the script that I am trying to use:

sed 's/[][a-z,0-9,A-Z,!@#\$%^&*(){}":/_-|. -][\;''=?]*//g' < $1 >Abhineet_extract1.txt;
sed 's/\(.\)/\1\
/g' <Abhineet_extract1.txt | sort | uniq |tr -d '\n' >&1;
rm Abhineet_extract1.txt;

and here is the error that I am getting:

uniq: stdin: Illegal byte sequence

'+?

1条回答
【Aperson】
2楼-- · 2019-04-09 11:53

It seems that a UTF-8 locale is causing Illegal byte sequence.

Instead say:

LC_CTYPE=C your_command

man locale says:

   These environment variables affect each locale categories for all
   locale-aware programs:

   LC_CTYPE

           Character classification and case conversion.
查看更多
登录 后发表回答