Created
September 1, 2019 12:16
-
-
Save psolm/fea19ec08acf02ad200a64ce0ae9ccbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
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
delete space and tab from start and end of line to file