| 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 |