Skip to content

Instantly share code, notes, and snippets.

@dex4er
Last active May 11, 2016
Embed
What would you like to do?
trim - convert all tabs to spaces and remove spaces at the end of lines
#!/bin/sh
die () {
echo "$@" 1>&2
exit 1
}
test -n "$1" || die "Usage: $0 file"
case "`stat --version 2>&1 | head -n1`" in
*GNU*)
stat="stat -c %a";;
*)
stat="stat -f %p";;
esac
while [ -n "$1" ]; do
test -f "$1" || die "Cannot open file: $1"
mode=`$stat "$1"`
col -x < "$1" | expand > "$1.tmp-trim" \
&& test -s "$1.tmp-trim" \
&& chmod $mode "$1.tmp-trim" \
&& mv -f "$1.tmp-trim" "$1"
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment