EXPAND(1) General Commands Manual EXPAND(1)

expand, unexpandexpand tabs to spaces, and vice versa

expand [-t tab1,tab2,...,tabn] [file ...]

unexpand [-a | -t tab1,tab2,...,tabn] [file ...]

The expand utility processes the named files or the standard input writing the standard output with tabs changed into blanks. Backspace characters are preserved into the output and decrement the column count for tab calculations. The expand utility is useful for pre-processing character files (before sorting, looking at specific columns, etc.) that contain tabs.

The unexpand utility puts tabs back into the data from the standard input or the named files and writes the result on the standard output.

The following options are available:

(unexpand only.) By default, only leading blanks and tabs are reconverted to maximal strings of tabs. If the -a option is given, then tabs are inserted whenever they would compress the resultant file by replacing two or more characters.
-Sm tab1, tab2, ..., tabn Sm
Set tab stops at column positions tab1, tab2, ..., tabn. If only a single number is given, tab stops are set that number of column positions apart instead of the default number of 8.

The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of expand and unexpand as described in environ(7).

The expand and unexpand utilities exit 0 on success, and >0 if an error occurs.

The expand and unexpand utilities conform to IEEE Std 1003.1-2001 (“POSIX.1”).

The expand utility first appeared in 1BSD.

June 6, 2015 macOS 15.2