Skip to content

Instantly share code, notes, and snippets.

@LightningStalker
Created February 23, 2026 17:24
Show Gist options
  • Select an option

  • Save LightningStalker/ad68eac5d9692d603a9149c2a337a56d to your computer and use it in GitHub Desktop.

Select an option

Save LightningStalker/ad68eac5d9692d603a9149c2a337a56d to your computer and use it in GitHub Desktop.
wa.sh : remove the trailing whitespace
#!/bin/bash
# wa.sh - rinse away the sin of trailing whitespace <- Project Crew™ 2/23/2026
PROGNAME=$(basename ${0})
if test -n "${1}"
then
if test -f "${1}"
then
NL=$(egrep -ch ' +$' ${1})
echo ${PROGNAME}: Found ${NL} line\(s\) ending in whitespace.
if test ${NL} -gt 0
then
echo ${PROGNAME}: Cleaning it up...
sed -i -r 's/ +$//' ${1}
else
echo ${PROGNAME}: Nothing to do.
fi
else
echo ${PROGNAME}: \'${1}\': File not found
fi
else
echo "${PROGNAME}: I can remove the trailing whitespace. Name a file."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment