Linux: Convert Tabs to Spaces

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 tool.

$ 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 :retab command.

:set tabstop=4
:retab

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react, vuejs); plays_on(xbox, ps4); linux_desktop_user(true); }