expand: To convert a tab space to space characters

expand: Command used to convert the tab space to separate space characters.

Example:

Let us say we we have a file “temp” with the following contents.

temp:

one 1 two 2 three 3 four 4

In each line we have one tab space, which is equivalent to 8 space characters. To convert this one tab space to 8 space characters we can run the command expand on the file.

$ expand temp > temp_1 $ cat temp_1 one 1 two 2 three 3 four 4

The new file “temp_1” looks the same as the file “temp” but if we open the file to edit it, we will encounter 8 space characters instead of tab on every line.

To change the number of space characters from 8 to any number of our choice we can use the option “-t”.

$ expand -t 1 temp one 1 two 2 three 3 four 4

We can see that the tab has been replaced by single space. The number that you specify after “-t” will be the number of spaces that will put instead of the tab space.

We can also restrict the command to work only at the beginning of a file by passing the option “-i”

Example :

Let us modify the file temp and add a tab at the beginning of the first line.

temp:

one 1 two 2 three 3 four 4

Now use expand on the file along with option “-i”

$ expand -i -t 1 temp one 1 two 2 three 3 four 4

We can see that only the tab at the beginning of the first line has been removed,but the rest of the tabs are intact.

Related Blogs


    Tags: ,
    Copyright 2017. All rights reserved.

    Posted July 23, 2012 by Tux Think in category "Linux