Changeset 30722 for other-projects

Show
Ignore:
Timestamp:
17.08.2016 17:18:21 (3 years ago)
Author:
ak19
Message:

Remove repeated empty lines, leaving just a single blank line between lines that were separated by many more blank lines.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • other-projects/gti/remove_extra_lines.sh

    r29457 r30722  
    44 
    55CLEANVERSION_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 
    610 
    711# echo $1 
     
    3337sed -e '/\s*#.*$/d' -e '/^\s*$/d' $1 > $CLEANVERSION_NAME 
    3438 
     39 
    3540# if the *.clean file is actually empty, print a message 
    3641# http://www.unix.com/shell-programming-and-scripting/21753-check-if-file-empty.html 
    3742if [[ ! -s $CLEANVERSION_NAME ]] ; then 
    3843    echo "@@@ $1 only has comments and empty lines/spaces." 
     44else 
     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 
    3963fi ; 
    4064rm $CLEANVERSION_NAME