sed -i '/^[ \t]*$/d' file-name
it will delete all empty lines that have any values. spaces (spaces or tabs), i.e. (0 or more) in the file.
NOte: there is a “space” in the square bracket followed by “\ t” ...
" -i " will force the updated contents to be written back to the file ... without this flag, you can see that empty lines were deleted on the screen, but the actual file will not be affected.
source share