Grep a file that may contain strange characters

Hello unix users :slight_smile:

I am trying to grep a string from a file that both the file and the string may have characters in them that are quite... strange, like w�rzburger.

Well, bash reads this as

W%C3%BCrzburger

For example, if i do

wget W%C3%BCrzburger

the output is:

--2012-01-08 02:54:29--  http://w%C3%BCrzburger/
Resolving w�rzburger... failed: Name or service not known.
wget: unable to resolve host address `w�rzburger'

On the other hand, if a file has this word inside it, and I do

cat file | grep W%C3%BCrzburger

i get no matching :confused:

Why is this? how can this be solved?
Many thanks :smiley:

grep w$'\xC3\xBC'rzburger /tmp/2

w�rzburger

cat /tmp/2:

wcrzburger
w�rzburger
wcrzburger

1 Like

Thanks, nice solution, it works as expected. The problem is that this grepping is part of a large script file, so, is there anything I can do so as to detect if the term I want to search contains not very usual letters like the above?

And if yes, then is there any way with which I can replace the %C3s etc with \xC3s so as to search the term, without possibly altering the rest of the string?

That seems a bit difficult :open_mouth: