Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

unexpand - convert spaces to tabs

&pagelevel(4)&pagelevel

The unexpand command writes files or the standard input to the standard output. Blanks at the beginning of each line are converted to the maximum number of tabs, followed by the minimum number of blanks needed to pad the line to the next tab stop, which were originally filled by the converted characters.

A tab stop is set after every 8 column positions by default. All backspace characters are copied to the output and cause the column position count for for tab stop calculations to be decremented. The column position count will not be decremented below zero.


Syntax


unexpand[ -a| -t tablist][ file...]

-a

Not only are the blanks at the start of each line converted, but also all sequences of two or more blanks directly in front of a tab stop are converted into the maximum number of tabs followed by the minimum number of blanks needed to pad the line to the next tab stop, which were originally filled by the converted characters.

-t tablist

Specifies the tab stops. The argument tablist must consist of one or more numbers, separated by blanks or commas, in ascending order. A list separated by blanks must be enclosed in quotes. If only one number is specified, the tab stops will be set to tablist column positions instead of the default 8 column positions.

If multiple numbers are given, the tabs will be set at the specified column positions.

Each tab stop position N must be an integer value greater than zero, and the specifications must be in ascending order. This means that tabbing from the start of the line of output to position N causes the next character output to be in the (N+1)th column position in that line.

For characters that are one position behind the last position defined in a list with multiple tab stops, there is no conversion of blanks into tabs.

If -t is specified, conversion of blanks is not restricted to the leading blanks. -a is ignored in this case.

file

The file whose blanks are to be replaced by tab characters.

Locale

The following environment variables affect the execution of unexpand:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determines the internationalized environment for the interpretation of byte sequences (e.g. single-byte characters as opposed to multi-byte characters in arguments and input files). The internationalized environment for the processing of tab characters and blanks and for the specification of the width in column positions each character would occupy on a constant-width output device.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Standard output (stdout)

The standard output is equivalent to the input files with blanks converted into the appropriate number of tabs.

Hint

The default behavior of unexpand, whereby only leading blanks are taken into consideration, may not be desired in some cases. Users who always want to convert all blanks in a file should use an alias definition to create a version of unexpand that is always called with the options -a or -t 8.

See also

expand, tabs