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

1

6

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

'+?

Fireresistant answered 23/9, 2013 at 7:17 Comment(0)
J
14

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.
Johst answered 23/9, 2013 at 7:29 Comment(4)
Thanks for your help. The error is gone but the output now contains only '+? characters. I was feeding the output from a sqlite query to the script. I formatted the output to csv and then my script started working.Fireresistant
It's not very clear what you're saying. Please update your question instead.Johst
I ran into this issue while deleting some sensitive data from my git history using git filter-branch --tree-filter "find . -type f -exec sed -i -e 's/originalpassword/newpassword/g' {} \;" and it worked like a charmErhart
So, is this an issue with Sort? does FreeBSD still suffer from this problem? or should I just file a bug with Apple and tell them to update their ancient ass bin/utils?Gonroff

© 2022 - 2024 — McMap. All rights reserved.