unexpand - convert spaces to tabs
unexpand [ -a| -t tablist][file...]
The unexpand utility copies files or standard input to standard output, converting blank characters at the beginning of each line into the maximum number of tab characters followed by the minimum number of space characters needed to fill the same column positions originally filled by the translated blank characters. By default, tabstops are set at every eighth column position. Each backspace character is copied to the output, and causes the column position count for tab calculations to be decremented; the count will never be decremented to a value less than one.
The unexpand utility supports the XBD specification, Utility Syntax Guidelines .
The following option is supported:
- In addition to translating blank characters at the beginning of each line, translate all sequences of two or more blank characters immediately preceding a tab stop to the maximum number of tab characters followed by the minimum number of space characters needed to fill the same column positions originally filled by the translated blank characters.
- -t tablist
- Specify the tab stops. The option-argument tablist must be a single argument consisting of a single positive decimal integer or multiple positive decimal integers, separated by blank characters or commas, in ascending order. If a single number is given, tabs will be set tablist column positions apart instead of the default 8. If multiple numbers are given, the tabs will be set at those specific column positions. Each tab-stop position N must be an integer value greater than zero, and the list must be in strictly ascending order. This is taken to mean that, from the start of a line of output, tabbing to position N will cause the next character output to be in the (N+1)th column position on that line. When the -t option is not specified, the default is the equivalent of specifying -t 8 (except for the interaction with -a, described below). No space-to-tab character conversions occur for characters at positions beyond the last of those specified in a multiple tab-stop list. When -t is specified, the presence or absence of the -a option is ignored; conversion will not be limited to the processing of leading blank characters.
The following operand is supported:
- A pathname of a text file to be used as input.
See the INPUT FILES section.
The input files must be text files.
The following environment variables affect the execution of unexpand:
- Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
- If set to a non-empty string value, override the values of all the other internationalisation variables.
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the processing of tab and space characters and for the determination of the width in column positions each character would occupy on a constant-width-font output device.
- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
- Determine the location of message catalogues for the processing of LC_MESSAGES .
The standard output is equivalent to the input files with the specified space to tab character conversions.
Used only for diagnostic messages.
The following exit values are returned:
- Successful completion.
- An error occurred.
One non-intuitive aspect of unexpand is its restriction to leading spaces when neither -a nor -t is specified. Users who desire to always convert all spaces in a file can easily alias unexpand to use the -a or -t 8 option.