Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Eli Zaretskii Newsgroups: gnu.utils.bug Subject: Re: Bug in grep.exe Date: Sat, 26 Aug 2017 14:04:58 +0300 Lines: 34 Approved: bug-gnu-utils@gnu.org Message-ID: References: Reply-To: Eli Zaretskii NNTP-Posting-Host: lists.gnu.org X-Trace: usenet.stanford.edu 1503745515 14893 208.118.235.17 (26 Aug 2017 11:05:15 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-gnu-utils@gnu.org To: Nicholas Hawthorn Envelope-to: bug-gnu-utils@gnu.org In-reply-to: (message from Nicholas Hawthorn on Sat, 26 Aug 2017 12:03:58 +1200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: bug-gnu-utils@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU utilities List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.utils.bug:2217 > From: Nicholas Hawthorn > 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.