This is the mail archive of the
mailing list for the Cygwin project.
Re: Bug: grep behaves incorrectly under the locale C.UTF-8, if a file contains Umlaut characters
- From: Erik Bray <erik dot m dot bray at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Wed, 24 May 2017 13:34:19 +0200
- Subject: Re: Bug: grep behaves incorrectly under the locale C.UTF-8, if a file contains Umlaut characters
- Authentication-results: sourceware.org; auth=none
- References: <1495612367.2760331.986814392.79C77EB2@webmail.messagingengine.com>
On Wed, May 24, 2017 at 9:52 AM, Ronald Fischer wrote:
> I have a file X which contains ASCII text, but also in some lines German
> umlaut characters. The file is classified as:
> $ file X
> X: ISO-8859 text, with CRLF line terminators
> If I grep the file using, say,
> $ grep . X >Y
> (i.e. select every non-empty line and write the result to Y), this works
> fine, if LANG is set to one of: UTF-8, C, C.de_DE, C.en_EN, en_EN,
> However, if LANG is set to C.UTF-8, two things happen:
> - grep classifies the file as binary file and produces the error message
> "Binary file X matches"
> - Both the grepped lines (i.e. in our example the non-empty lines) AND
> the error message end up in the standard output (i.e. in file Y).
> IMO, there are several problems with this:
> 1. It's hard to see, why an umlaut character makes the file X binary
> under encoding C.UTF-8, but not under encoding UTF-8 or C.en_EN
Only one of these, "UTF-8", specifies an *encoding*. Further, I don't
think just "UTF-8" or "C.en_EN" are valid locale specifiers. You can
read more about how Cygwin handles locales here:
Certainly, if you set something like LANG="C.UTF-8" it will use UTF-8
to decode the text in the file and, failing that, treat it as binary.
If you know it's ISO-8859-1 you can use either LANG= or
LC_CTYPE="C.ISO-8859-1". Or, if you know the language, you should be
able to use LC_CTYPE="de_DE". Each language+territory has a default
encoding associated with it. For German I think it is one of the
ISO-8859-* variants. Or you can use the variant "de_DE@euro" which
forces ISO-8859-15 which includes the euro symbol, among other
possibilities. So I think your main problem here is just not
specifying your locale correctly.
> 2. If grep classifies a file as binary, I think the desired behaviour
> would be to NOT produce any output, unless the -a flag has been
> 3. If grep writes a message "Binary file ... matches", this message
> should go to stderr, not stdout. The stdout is supposed to contain only
> a subset of the input lines.
I would tend to agree with this, but this is normal behavior of grep
(on Linux too), so I would take it up with the authors of grep.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple