Objective: Convert a text file with tabs to spaces on Linux.
There are various tools to convert tabs to spaces. One of the them is the
$ expand input.txt > output.txt
To convert a single tab to 4 spaces, use the following syntax.
$ expand -t 4 input.txt > output.txt
If you are only interested in replacing the initial tab-based indents with spaces in your source code files and not convert any tabs defined in strings, use
expand with “-i” option.
$ expand -i -t 4 input.c > output.c
To convert a tab into 4 spaces using
sed, use the following syntax.
$ sed -e 's/\t/ /g' input.txt > output.txt
If you are editing a file in vim, use
:set tabstop=4 :retab