[Openais] trailing blanks have snuck back in

Jim Meyering jim at meyering.net
Fri Jun 19 04:33:04 PDT 2009


Jim Meyering wrote:
> I've just rebased my "use gnulib' patch,
> part of which adds the "make syntax-check" rule.
> One of its checks is to ensure there are no trailing
> blanks in version-controlled files.  That one failed with
> many complaints.
>
> I fixed them all with this:
>
>     perl -pi -e 's/[ \t]+$//' $(git grep -E '[[:blank:]]+$')

Oops.  That's not quite right. (missing -l)  This works better:

    perl -pi -e 's/[ \t]+$//' $(git grep -l -E '[[:blank:]]+$')

However, that still fails if you have so many offenders that
their names overflow the shell's command-line length limit.
In that case, use xargs

    git grep -l -E '[[:blank:]]+$' | xargs perl -pi -e 's/[ \t]+$//'

But that can fail, too, if you have a version-controlled file
with a name containing a newline.  Don't do that.

But if you really must, this is robust:

    git grep -z -l -E '[[:blank:]]+$' | xargs -0 perl -pi -e 's/[ \t]+$//'


More information about the Openais mailing list