You may have spaces or tabs in your “empty” line. Use POSIX classes with sed
to remove all lines containing only whitespace:
sed '/^[[:space:]]*$/d'
A shorter version that uses ERE, for example with gnu sed:
sed -r '/^\s*$/d'
(Note that sed does NOT support PCRE.)
More Related Contents:
- Environment variable substitution in sed
- Better way to rename files based on multiple patterns
- How can I remove the last character of a file in unix?
- Uppercasing First Letter of Words Using SED
- Using grep and sed to find and replace a string
- Bash script to remove ‘x’ amount of characters the end of multiple filenames in a directory?
- grep lines that contain 1 character followed by another character
- When should I wrap quotes around a shell variable?
- How to convert DOS/Windows newline (CRLF) to Unix newline (LF) in a Bash script
- sed command with -i option failing on Mac, but works on Linux
- What’s the magic of “-” (a dash) in command-line parameters?
- What is double dot(..) and single dot(.) in Linux?
- What does the number in parentheses shown after Unix command names in manpages mean?
- Forcing bash to expand variables in a string loaded from a file
- How to convert DOS/Windows newline (CRLF) to Unix newline (LF)
- How to instruct cron to execute a job every second week?
- How do I use the lines of a file as arguments of a command?
- How to insert a text at the beginning of a file?
- How can I programmatically create a new cron job?
- How to concatenate multiple lines of output to one line?
- What is a .pid file and what does it contain?
- GROUP BY/SUM from shell
- List files recursively in Linux CLI with path relative to the current directory
- What is the difference between “source script.sh” and “./script.sh”?
- How to print third column to last column?
- Monitor Directory for Changes
- Insert multiple lines into a file after specified pattern using shell script
- How can I use xargs to copy files that have spaces and quotes in their names?
- How to use sed to extract substring
- Find all files with name containing string [closed]