expand, unexpand - Replaces tab characters with spaces or spaces with tab characters
expand [-t tablist] [file...]
unexpand [-a|-t tablist] [file...]
expand [-tabstop|-tab1,tab2,...,tabn] [file...]
Interfaces documented on this reference page conform to industry standards as follows:
expand: XPG4, XPG4-UNIX
unexpand: XPG4, XPG4-UNIX
Refer to the
reference page for more information
about industry standards and associated tags.
Replaces spaces at the beginning of each line with a tab, and inserts tab characters wherever their presence compresses the resultant file by replacing two or more characters. When the -t option is specified with the unexpand command, the -a option has no effect. (This option applies to the unexpand command only.) Specifies the tab stops. The tablist argument consists of a single positive decimal integer or multiple positive decimal integers, separated by spaces or commas, in ascending order. If a single number is specified, tabs are set tablist column positions apart instead of the default (8). If multiple numbers are specified, tabs are set at those specific column positions. Tabbing to tab stop position n thus causes the next character output to be in the (n+1)th column position on that line.
The path name of a file to be processed. If you do not specify
this operand, standard input is read.
The expand command changes tab characters to spaces in the named files, or the standard input, and writes the result to the standard output.
The unexpand command puts tab characters into the data from the standard input, or the named files, and writes the result to the standard output.
Backspace characters are preserved in the output and decrement the column count for tab calculations. The column position count cannot be decremented below one. The expand command is useful for preprocessing character files (before sorting, looking at specific columns, and so on.) that contain tab characters.
converts only spaces that are
within sequences of spaces and tab characters at the beginnings of lines.
to convert other sequences of spaces.
If the expand command encounters difficulties opening any specified file, it writes an error message to standard error and terminates immediately with an error status.
command encounters difficulties opening
file, it writes an error message
to standard error and continues operation. The exit status will reflect the
The following exit values are returned by either command:
An error occurred.
To replace tab characters in file with spaces, enter: expand file To replace the spaces in file with tab characters, enter: unexpand -a file
The following environment variables affect the execution of
Provides a default value for the internationalization variables
that are unset or null. If
is unset or null, the corresponding value from the default locale is used.
If any of the internationalization variables contain an invalid setting, the
utility behaves as if none of the variables had been defined.
If set to a non-empty string value, overrides the values of
all the other internationalization variables.
Determines the locale for the interpretation of sequences
of bytes of text data as characters (for example, single-byte as opposed to
multibyte characters in arguments).
Determines the locale for the format and contents of diagnostic
messages written to standard error.
Determines the location of message catalogues for the processing
Commands: fold(1), tabs(1)