Changeset 30722
- Timestamp:
- 2016-08-17T17:18:21+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/gti/remove_extra_lines.sh
r29457 r30722 4 4 5 5 CLEANVERSION_NAME="$1.clean" 6 7 # http://stackoverflow.com/questions/2613800/how-to-convert-dos-windows-newline-crlf-to-unix-newline-n-in-bash-script 8 #sed $'s/\r$//' $1 > $CLEANVERSION_NAME 9 #mv $CLEANVERSION_NAME $1 6 10 7 11 # echo $1 … … 33 37 sed -e '/\s*#.*$/d' -e '/^\s*$/d' $1 > $CLEANVERSION_NAME 34 38 39 35 40 # if the *.clean file is actually empty, print a message 36 41 # http://www.unix.com/shell-programming-and-scripting/21753-check-if-file-empty.html 37 42 if [[ ! -s $CLEANVERSION_NAME ]] ; then 38 43 echo "@@@ $1 only has comments and empty lines/spaces." 44 else 45 46 47 # remove empty newlines, modifying the file in place. 48 # http://stackoverflow.com/questions/16414410/delete-empty-lines-using-sed 49 # http://unix.stackexchange.com/questions/76061/can-sed-remove-double-newline-characters 50 #sed -i '/^$/d' $1 51 52 53 # remove empty spaces from lines that are purely empty spaces, but leave 54 # the newline intact, as we'll remove it further below. 55 sed -e 's/^\s*$//' $1 > $1.tmp 56 57 # If there's multiple new lines (3 or more) make them just 2. So leave 58 # one blank line between lines wherever there were many more blank lines 59 # http://stackoverflow.com/questions/922449/how-can-i-replace-mutliple-empty-lines-with-a-single-empty-line-in-bash 60 # "cat with the -s option causes it to remove repeated empty lines from its output" 61 # Beware: on Solaris, the -s option to cat can mean "cat is silent about missing files" 62 cat -s $1.tmp > $1 39 63 fi ; 40 64 rm $CLEANVERSION_NAME
Note:
See TracChangeset
for help on using the changeset viewer.