How to remove tabs from blank lines using sed?

SundayMonday picture SundayMonday · Sep 26, 2011 · Viewed 41.4k times · Source

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?

Answer

Hari Menon picture Hari Menon · Sep 26, 2011

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.