unexpand(1)
Convert spaces to tabs in text files.
Synopsis
unexpand [OPTION]... [FILE]...Description
The unexpand command replaces leading sequences of spaces with tabs in input lines. By default, it converts spaces at the beginning of lines and between words to tabs, useful for reducing file size or reformatting code to use tab indentation.
If no files are specified, unexpand reads from standard input. Output is written to standard output unless the -i option is used to modify files in place.
Common options
| Flag | What it does |
|---|---|
-a, --all | Convert all spaces (not just leading) to tabs, using tab stops every 8 characters by default |
-t, --tabs=N | Set tab stops at N characters apart (default 8); can specify multiple positions with commas |
-i, --in-place | Modify files in place instead of writing to standard output |
--first-only | Only convert spaces before the first non-space character on each line |
--help | Display help message and exit |
--version | Output version information and exit |
Examples
Convert leading spaces to tabs in file.txt and display result to stdout
unexpand file.txtConvert all spaces (not just leading) to tabs throughout the entire file
unexpand -a file.txtUse tab stops every 4 characters instead of the default 8
unexpand -t 4 file.txtModify all .py files in place, converting spaces to tabs
unexpand -i *.pyPipe file through unexpand and view result with less pager
cat file.txt | unexpand -a | lessConvert only leading spaces before the first non-space character on each line
unexpand --first-only code.c