Skip to content

Instantly share code, notes, and snippets.

@fallwith
Created May 16, 2010 06:03
Show Gist options
  • Save fallwith/402702 to your computer and use it in GitHub Desktop.
Save fallwith/402702 to your computer and use it in GitHub Desktop.
# Use Ack to find offending source files and Perl to perform the following:
# convert Windows newlines to unix newlines
# convert tabs to two spaces
# strip trailing whitespace
ack " +$|\t|\r" -l|xargs perl -pi -e "s/\r\n?/\n/g;s/\t/ /g;s/[ ]*$//g"
# Implement a clean() method in Bash:
# Clean up source code by converting tabs to 2 spaces, Windows newlines to
# unix ones, and by stripping away trailing whitespace. Pass in a list of
# files to clean, or let ack find a list of suitable candidates.
clean() {
if [ $1 ]; then
files=$@
else
files=`ack " +$|\t|\r" -l`
fi
echo $files|xargs perl -pi -e "s/\r\n?/\n/g;s/\t/ /g;s/[ ]*$//g"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment