Add this filter to remove the space from the beginning of the line and remove the empty lines, note that it uses two sed commands, one to remove leading spaces and the other to delete lines without content
| sed -e 's/^\s*//' -e '/^$/d'
The following is an example of a Wikipedia article for sed that uses the d command to delete lines that are empty or contain only spaces, my solution uses the \s escape sequence to match any space character (space, tab, etc.), here Wikipedia example:
sed -e '/^ *$/d' inputFileName
- The carriage (^) matches the beginning of a line.
- The dollar sign ($) matches the end of the line.
- An asterisk (*) matches zero or more occurrences of the previous character.
source share