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

Tags:


ATOzTOA : Latest Headlines


7 comments:

Jadu Saikia said...

The tab can be generated by the following also.

Ctrl + V and then Ctrl + I

http://unstableme.blogspot.com/search/label/Sed

atoztoa said...

Hi Jadu,

Any ways to replace Newline character?

Jadu Saikia said...

a’tu’tua,

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

http://unstableme.blogspot.com/2008/05/remove-or-replace-newlines-using.html

// 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: http://www.regular-expressions.info/posixbrackets.html

Post a Comment