Recently in One-liners Category

This is a "one-liner" that I use sometimes to find files that contain carriage returns.  Some files containing carriage returns were committed to a Subversion repository that I manage. These files caused the diff to be corrupt when diffing against a file without the \r.  Not a huge issue, but annoying.

This command basically uses a for loop with find to recursively list all files starting from the current directory.  In the loop, each file is dumped into a small Perl one-liner that checks each line for a \r and increments a counter.  The grep at the end filters out all files with a zero count.  You could change \r to anything you want to find.

prompt:~# for a in `find . -type f`; do echo -n "$a: "; perl -e 'my $cr = 0; while (<STDIN>){ $cr += tr/\r//; } print $cr;' < $a; echo; done | grep -v '0$'

This produces a list of files with a count of characters found.

./someapp.cgi: 36
./anotherapp.cgi: 41
./somedir/yetanother.cgi: 199

Pages

About this Archive

This page is an archive of recent entries in the One-liners category.

General Development is the previous category.

Perl is the next category.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.261