Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "sed error - illegal byte sequence" (in bash) [duplicate]

Tags:

bash

sed

Doing some stream editing to change the nasty Parallels icon. It's poorly developed and embedded into the app itself rather than being an image file. So I've located this sed command that has some good feedback:

sudo sed -i.bak s/Parallels_Desktop_Overlay_128/Parallels_Desktop_Overlay_000/g /Applications/Parallels\ Desktop.app/Contents/MacOS/prl_client_app

It returns sed: RE error: illegal byte sequence

Can anyone explain what this means? What part of the command is the problem?

like image 609
alt Avatar asked Jul 02 '12 03:07

alt


4 Answers

Try setting the LANG environment variable (LANG=C sed ...) or use one of the binary sed tools mentioned here: binary sed replacement

Why the error?

Without LANG=C sed assumes that files are encoded in whatever encoding is specified in LANG and the file (being binary) may contain bytes which are not valid characters in LANG's encoding (thus you could get 'illegal byte sequence').

Why does LANG=C work?

C just happens to treat all ASCII characters as themselves and non-ASCII characters as literals.

like image 92
ldrg Avatar answered Nov 06 '22 14:11

ldrg


LANG=C alone didn't do the trick for me but adding LC_CTYPE=C as well solved it.

like image 37
Malström Avatar answered Nov 06 '22 15:11

Malström


In addition to LANG=C and LC_CTYPE=C, I had to do LC_ALL=C to get this to work.

LC_ALL overrides all individual LC_* categories. Thus, the most robust approach is to use LC_ALL=C sed ... - no need to also deal with the other variables.

like image 33
rjpeter2 Avatar answered Nov 06 '22 14:11

rjpeter2


I managed to do it by running:

unset LANG

before the sed command.

Not sure what I've done or why it works but it did.

like image 24
Adam Waite Avatar answered Nov 06 '22 13:11

Adam Waite