Linux Commands - expand (replace tabs with spaces)

by
Jeremy Canfield |
Updated: March 09 2020
| Linux Commands articles
The expand command can be used to change a file to be separated with spaces instead of tabs, and the unexpand command can be used to change a file to be separated with tabs instead of spaces. In this example, each word in file 1 is separated by a tab.
[root@server1 ]# cat file1
Hello world
How are you today?
The cat command with the -T or --show-tabs and -e (show line feed) options can be used to be absolutely certain that file1 is delimited with tabs. The ^I character represents a tab and $ represents a line feed.
[root@server1 ]# cat -te file1
Hello^Iworld$
How^Iare^Iyou^Itoday?$
The expand command with the -t or --tabs option can be used to change a tab into a space. In this example, each tab is changed to 1 space.
[root@server1 ]# expand --tabs=1 file1
Hello world
How are you today?
Did you find this article helpful?
If so, consider buying me a coffee over at