bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in grep.exe


From: Eli Zaretskii
Subject: Re: Bug in grep.exe
Date: Sat, 26 Aug 2017 14:04:58 +0300

> From: Nicholas Hawthorn <address@hidden>
> Date: Sat, 26 Aug 2017 12:03:58 +1200
> 
> Say we make a one line text file called "a" that contains
>     w  CR  LF
> 
> and then give the command:
>     grep -v "<" < a > b
> 
> File "b" will consist of:
>     w  LF
> 
> In effect, grep has removed the CR.

Yes, and this is a feature.  The exact command-line arguments are
unimportant: Grep on Windows _always_ strips CR characters from
Windows-style CRLF EOLs, and never adds them back when writing output
to files or pipes.  This is because the alternative, of always adding
CR to LF-only Unix-style EOLs, which is what Windows text-mode output
would do, is much worse and will break many scripts and test suites.
It would also make it impossible to output anything past the first ^Z
byte, which serves as a "software EOF" indicator.

> The bug was first found in a 66 line .bat file where it was a bit of
> a nuisance.

Why is that a problem in a batch file?  AFAIK, the stock Windows shell
in modern versions of MS-Windows has no problems running batch files
with Unix-style LF-only EOLs, unlike on old versions of the OS.

P.S. I think (but I'm not sure) latest versions of Grep removed this
feature, so perhaps you will be better off if you upgrade your Grep
installation.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]