| 1 | #!/bin/bash |
| 2 | |
| 3 | # This simple script removes blank lines from a file. |
| 4 | # No argument checking. |
| 5 | # |
| 6 | # You might wish to add something like: |
| 7 | # |
| 8 | # E_NOARGS=85 |
| 9 | # if [ -z "$1" ] |
| 10 | # then |
| 11 | # echo "Usage: `basename $0` target-file" |
| 12 | # exit $E_NOARGS |
| 13 | # fi |
| 14 | |
| 15 | |
| 16 | |
| 17 | sed -e /^$/d "$1" |
| 18 | # Same as |
| 19 | # sed -e '/^$/d' filename |
| 20 | # invoked from the command-line. |
| 21 | |
| 22 | # The '-e' means an "editing" command follows (optional here). |
| 23 | # '^' indicates the beginning of line, '$' the end. |
| 24 | # This matches lines with nothing between the beginning and the end -- |
| 25 | #+ blank lines. |
| 26 | # The 'd' is the delete command. |
| 27 | |
| 28 | # Quoting the command-line arg permits |
| 29 | #+ whitespace and special characters in the filename. |
| 30 | |
| 31 | # Note that this script doesn't actually change the target file. |
| 32 | # If you need to do that, redirect its output. |
| 33 | |
| 34 | exit |