I'm trying to find lines with the carriage return character, but I'm not getting the results I'd expect. I've whittled it down to this proof-of-concept:
$ uname -a
CYGWIN_NT-6.1 Aodh 2.0.4(0.287/5/3) 2015-06-09 12:22 x86_64 Cygwin
$ grep --version
grep (GNU grep) 2.21
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
$ od -c cr_poc.txt
0000000 h e l l o w o r l d ; \r \n \r \n
0000020
$ od -x cr_poc.txt
0000000 6568 6c6c 206f 6f77 6c72 3b64 0a0d 0a0d
0000020
$ grep $'\r' cr_poc.txt; echo $?
1
I've tried various other ways of grepping for the \r
character, but none have worked.
Notice this is on Cygwin, which certainly could be part of the problem.
Best Answer
Poking around with various inputs, I felt
grep
did its own magic for line-endings:(The
-z
was my lame attempt to makegrep
match everything.) And so I searched the manpage forLF
, leading me to: