Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Illegal Byte sequence" error while using shell commands in mac bash terminal

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

'+?

like image 523
Abhineet Prasad Avatar asked Sep 23 '13 07:09

Abhineet Prasad


1 Answers

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.
like image 148
devnull Avatar answered Sep 28 '22 18:09

devnull