Web lists-archives.com

Re: grep 3.0-2 not stripping CRs on Windows

On 12/17/2018 8:05 AM, Steven Penny wrote:
On Mon, 17 Dec 2018 13:22:48, Ondřej Surý wrote:
# No amount of options makes the grep find the text in the file
$ ./grep-3.0-2.exe 'foo$’ crlf.txt
$ ./grep-3.0-2.exe -U 'foo$' crlf.txt
$ ./grep-3.0-2.exe -a 'foo$’ crlf.txt

Your commands are failing because you are not accounding for the carriage
returns. as was said, this change was intentionally done for the purpose of
making scripts MORE portable:

And the portability is what we want to keep.


if you want to keep your grep command, you need to remove CR first:

    $ printf 'alpha\r\nbeta\r\n' > CRLF.txt
    $ tr -d '\r' < CRLF.txt | grep 'a$'

This is the POSIX method to get portability and Cygwin is POSIX for Windows. Therefore the bits of documentation for MS-DOS and MS-Windows isn't in affect for Cygwin grep. In other words the following is in affect but can be misinterpreted because Cygwin runs on MS-Windows but isn't considered such.

"This option has no effect on platforms other than MS-DOS and MS-Windows."


cyg Simple

Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple