Tuesday, August 21, 2007

Convert Tab to Specified Number of Spaces

You can also use the expand utility to specify the number of spaces between a tab. See below for an illustration.

Original file with tabs
# cat -v -t esoftfile
esoft^Iesoft^Iesoft^Iesoft
esoft^Iesoft^Iesoft^Iesoft
esoft^Iesoft^Iesoft^Iesoft
esoft^Iesoft^Iesoft^Iesoft
esoft^Iesoft^Iesoft^Iesoft

Convert tab to 20 spaces
# expand -20 esoftfile | cat -t -v
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft

Convert tab to 10 spaces
# expand -10 esoftfile | cat -v -t
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft

Convert tab to 2 spaces
# expand -2 esoftfile | cat -v -t
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft
esoft esoft esoft esoft

1 comment:

Anonymous said...

It's kind of hard to see what's happening since all the spaces display as a single space.

Here's some other ways to convert tabs to spaces in Unix:
http://mlawire.blogspot.com/2009/07/convert-tabs-to-spaces.html