How can I match a unix line ending with grep? I already have a working script that uses unix2dos
and cmp
, but it's a bit slow, and a single grep command would fit in a lot better with the rest of my bash code.
I tried using a negative lookbehind on '\r'
.
$ printf "foo\r\n" | grep -PUa '(?<!'$'\r'')$'
foo
Why doesn't that work? For the record, the regex pattern seems to evaluate just well this way:
$ printf '(?<!'$'\r'')$' | od -a
0000000 ( ? < ! cr ) $
0000007
Update:
$ grep --version
grep (GNU grep) 2.24
on MINGW64 on windows 7.
\r
, just use'(?<!\r)\n'
printf "foo\n" | grep -PUa '(?<!\r)\n'
shows no matchgrep (GNU grep) 2.25
$ printf "foo\n" | grep -PUa '(?<!'$'\r'')$'
does?