I'm trying to use a sed
one-liner to remove trailing newlines using one of the handy sed one-liners:
sed --in-place -e :a -e '/^\n*$/{$d;N;ba}'
It works for UNIX-style newlines, but doesn't for DOS-style newlines.
Despite the fact that I couldn't exactly get my head around sed
scripting syntax and matching rules, I tried this:
sed --binary --in-place -e :a -e '/^\(\r\?\n\)*$/{$d;N;ba}'
but it didn't help, and I don't really know why.
I don't really want to use Perl, etc., I want to stick to more "core" utilities.
So, are there any sed
gurus around? I would really appreciate your help.
I'm using Cygwin's distribution of sed
.
Thank you.
Specifically, I want this file (printed out using cat -A
):
1^M$
^M$
^M$
to become this:
1$