I have a file with some lines likes
x
y
and when I run
grep -E "x$" filename.txt
it does not match anything. As vi shows ^M in the end of most lines, I guess the problem is mixed Dos and Unix newlines and grep autodetecting the format.
I tried
grep --color=never -E "x.$" filename.txt
to match the extra \r in the end of the line and it works, but it prints a single \r and thus breaks when, for example, --color=always adds terminal control characters.
What I need is an option, to match both \r\n$ and \n with $.
Hexdump of an example file:
00000000 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 |xxxxxxxxxxxxxxxx| 00000010 78 78 78 78 78 78 78 78 78 78 78 0d 0a 79 0a |xxxxxxxxxxx..y.|
You can see the DOS line end and the unix line end. The output of grep -E --color=always "x.$" seems to be empty when grep -E --color=never "x.$" prints the line, probably containing the carriage return \r that is matched by the ..
xif you have aliased grep togrep --color=autofor example. What doesgrep -E --color=never "x.$" filename.txtor\grep -E "x.$" filename.txtshow?hexdump -C--color=neverit works. I think I get why it works (I don't get why it clears the line even when the line is very long, though). But what I really need is to have$match both $\n$ and\r\nin the same file without printing single\rcharacters.