Replace tabs with spaces in a file using the EXPAND command in Linux

Home > Search > Linux commands
  by

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?

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments