Skip to content

Instantly share code, notes, and snippets.

@psolm
Created September 1, 2019 12:16
Show Gist options
  • Save psolm/fea19ec08acf02ad200a64ce0ae9ccbc to your computer and use it in GitHub Desktop.
Save psolm/fea19ec08acf02ad200a64ce0ae9ccbc to your computer and use it in GitHub Desktop.
#auther peyman soleymani
#date 1/sep/2019
#!/bin/bash
#./space.sh [file-path] [-f | --fix] [-h | --help]
function usage() {
echo "USAGE: $0 [file-path] [-f | --fix] [-h | --help]"
exit 1
}
FIX=0 #0-do not perform fix 1-perform fix
if [ $# -eq 0 ]; then
usage
fi
while [ $# -gt 0 ]
do
case "$1" in
-f|--fix )
FIX=1
shift
;;
-h|--help )
usage
shift
;;
* )
if [ -f "$1" ]; then
FILE="$1"
shift
else
usage
fi
;;
esac
done
if [ $FIX -eq 1 ] && [ -f "$FILE" ]; then
echo "fixing space and tab at the beginning and at the end of line"
sed -i 's/[[:blank:]\+$]//' "$FILE"
sed -i 's/^[[:blank:]]\+//' "$FILE"
echo "DONE"
fi
#display graghicaly space error
if [ -f "$FILE" ]; then
while IFS= read -r line
do
#if there is no space issue on a line, just prinr the line
echo "$line" | sed -e '/[[:blank:]]\+$/q9' -e '/^[[:blank:]]\+/q7' >/dev/null
if [ $? -eq 0 ]; then
echo "$line"
continue
fi
done < "$FILE"
fi
@psolm
Copy link
Author

psolm commented Sep 1, 2019

delete space and tab from start and end of line to file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment