Replace Tab using Sed

Monday, December 22, 2008

Replace Tab using Sed

How to replace tabs with spaces using sed...

sed -i 's/[--TAB--]/ /g' file.txt

In place of --TAB-- , give CTRL + V followed by TAB.

This command will replace all tabs with 3 spaces in the file file.txt.

See also... » Effective Use of VIM - Part 4

» Linux Commands I Hardly Knew


ATOzTOA : Latest Headlines


Jadu Saikia said...

The tab can be generated by the following also.

Ctrl + V and then Ctrl + I

atoztoa said...

Hi Jadu,

Any ways to replace Newline character?

Jadu Saikia said...


I have a post on removing newlines using sed, awk, tr.

// Jadu

kotnik said...

No need for escaping stuff, you can just put:

sed -i 's/\t/ /g' file.txt

Anonymous said...

@kotnik No you can't, this will just search for the letter "t".

Anonymous said...

sed -r 's/[[:blank:]]/ /g'

This will replace spaces and tabs, with spaces.

More bracket expressions:

Post a Comment