unexpand - Compress spaces into tabs

Format

unexpand [-Ba] [-t tablist] [-W option[option] ... [file ...]

Description

unexpand replaces blank characters in the data from each file argument with the most efficient use of tabs and spaces. If you do not specify any files, unexpand reads the standard input. The result is sent to standard output.

Backspace characters are preserved. By default, unexpand compresses only leading spaces into tabs; tab stops are set every eight spaces.

Options

unexpand supports the following options:
-B
Disables the automatic conversion of tagged files. This option is ignored if the filecodeset or pgmcodeset options (-W option) are specified.
-a
Compresses spaces into tabs wherever the resulting output is shorter, regardless of where the spaces occur in the line.
-t tablist
Specifies tab stops. The numbers in tablist are delimited by blanks or commas. If tablist is a single number, then unexpand places tab stops every tablist positions. If tablist contains multiple numbers, unexpand places tab stops at those specific positions. Multiple numbers in tablist must be in ascending order. This option, like the -a option, compresses spaces to tabs at any appropriate point in the line. If you specify -t, unexpand ignores the presence or absence of -a.
-W option[,option]...
Specifies z/OS-specific options. The option keywords are case-sensitive. Possible options are:
filecodeset=codeset
Performs text conversion from one code set to another when reading from the file. The coded character set of the file is codeset. codeset can be a code set name known to the system or a numeric coded character set identifier (CCSID). Note that the command iconv -l lists existing CCSIDs along with their corresponding code set names. The filecodeset and pgmcodeset options can be used on files with any file tag.

If pgmcodeset is specified but filecodeset is omitted, then the default file code set is ISO8859-1 even if the file is tagged with a different code set. If neither filecodeset nor pgmcodeset is specified, text conversion will not occur unless automatic conversion is enabled or the _TEXT_CONV environment variable indicates text conversion. For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.

If filecodeset or pgmcodeset is specified, then automatic conversion is disabled for this command invocation and the -B option is ignored if it is also specified. For more information about automatic conversion, see Converting files between code pages in z/OS UNIX System Services Planning.

When specifying values for filecodeset, use the values that Unicode Service supports. For more information about supported code sets, see z/OS Unicode Services User's Guide and Reference.

pgmcodeset=codeset
Performs text conversion from one code set to another when reading from the file. The coded character set of the program (command) is codeset. codeset can be a code set name known to the system or a numeric coded character set identifier (CCSID). Note that the command iconv -l lists existing CCSIDs along with their corresponding code set names. The filecodeset and pgmcodeset options can be used on files with any file tag.

If filecodeset is specified but pgmcodeset is omitted, then the default program code set is IBM-1047. If neither filecodeset nor pgmcodeset is specified, text conversion will not occur unless automatic conversion is enabled or the _TEXT_CONV environment variable indicates text conversion. For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.

If filecodeset or pgmcodeset is specified, then automatic conversion is disabled for this command invocation and the -B option is ignored if it is also specified. For more information about automatic conversion, see Converting files between code pages in z/OS UNIX System Services Planning.

The only supported values for pgmcodeset are IBM-1047 and 1047.

Examples

  1. To compress spaces in a text file into tabs every 3 positions:
    unexpand -t 3 myTextFile
  2. To compress spaces in a text file containing ASCII characters into tabs, assuming that
    • The text file is untagged and you do not want to tag it or enable automatic conversion, and
    • You cannot alter the tag (for example, you are displaying an untagged public text file or a read-only text file)
    then issue:
    unexpand -a -W filecodeset=ISO8859-1,pgmcodeset=IBM-1047 myAsciiFile
  3. To compress spaces in a text file containing EBCDIC characters into tabs, assuming that automatic conversion has been enabled but the text file is incorrectly tagged as UTF-8:
    unexpand -a -B myMisTaggedFile 

Localization

unexpand uses the following localization variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • NLSPATH

Environment variables

unexpand uses the following environment variable:
_TEXT_CONV
Contains text conversion information for the command. The text conversion information is not used when either the -B option or the filecodeset or pgmcodeset option (-w option) is specified. For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.

Exit values

0
Successful completion
1
Failure due to any of the following reasons:
  • An incorrect command-line argument.
  • An inability to open the input files.
  • The code set is not valid.
  • Could not turn off automatic conversion.
  • Could not perform requested text conversion.

Portability

POSIX.2 User Portability Extension, X/Open Portability Guide, 4.2BSD.

The -B and -W options are extensions of the POSIX standard.

Related information

expand, pr