I'd like to use sed to remove tabs from otherwise blank lines. For example a line containing only \t\n should change to \n. What's the syntax for this?
sed does not know about escape sequences like \t. So you will have to literally type a tab on your console:
sed 's/^ *$//g' <filename>
If you are on bash, then you can't type tab on the console. You will have to do ^V and then press tab. (Ctrl-V and then tab) to print a literal tab.
To replace arbitrary whitespace lines with an empty line, use
sed -r 's/^\s+$//'
The -r flag says to use extended regular expressions, and the ^\s+$ pattern matches all lines with some whitespace but no other characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With