:
# Simple script that removes all trailing whitespace (tabs and spaces) from
# the standard input or a specified file.  It also compresses all leading
# black space to tabs.

# Created by Kevin O'Connor.

if [ "$1" = "" ]; then
    sed -e 's/[	 ]*$//' -e ':rep
			   { s/^\(	*\) \{8\}/\1	/
			     s/^\(	*\) \{1,7\}	/\1	/
			     t rep
			     }'
else
    mv "$1" "$1.strip!"
    sed -e 's/[	 ]*$//' -e ':rep
			   { s/^\(	*\) \{8\}/\1	/
			     s/^\(	*\) \{1,7\}	/\1	/
			     t rep
			     }' < "$1.strip!" > "$1"
    rm "$1.strip!"
fi
