Hitachi

Job Management Partner 1 Version 10 Job Management Partner 1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide


expand command (replaces tab characters with spaces)

Organization of this page

Format

expand[-tab-stop-list)][-t tab-stop-list][path-name ...]

Description

This command replaces the tab character with spaces in a line in which tab stops are set and then outputs the result to the standard output. If the tab character is followed by the backspace character, the column width for tabs is reduced in the output results.

One record delimited by an end-of-line code in the input file is treated as one line. In Windows, [CR]+[LF] or [LF] is treated as the end-of-line code; in UNIX, [LF] is treated as the end-of-line code. In UNIX, if a record in the input file is delimited by [CR]+[LF], the output result after conversion will contain [CR].

Arguments

-tab-stop-list

The function of this argument is the same as for -t tab-stop-list.

-tab-stop-list can be specified together with -t tab-stop-list, in which case all the specifications are effective.

-t tab-stop-list

--tabs=tab-stop-list

Specifies a list of the locations for tab stops, each as 1 or a greater integer. If this option is omitted, default tab stop 8 is used, which is the same as when one tab stop location is specified.

The following explains the command processing when one tab stop location is specified in the tab-stop list and when multiple tab stop locations are specified in the tab-stop list:

When one tab stop location is specified:

The command uses the specified value as the character spacing between equidistant tab stops.

When the tab character contained in one tab stop is replaced with spaces, the numbers of spaces between tab stops are adjusted to obtain the specified character spacing.

When multiple tab stop locations are specified:

The command uses each specified value as the column location for a tab stop. The column locations begin from 0.

The following explains how to specify multiple tab stop locations.

  • Specify multiple tab stop locations in the tab-stop list separating them with the comma or space.

    To use the space as the separator, enclose it in double-quotation marks (").

    When the tab characters contained in the tab stops are replaced with spaces, the numbers of spaces between tab stops are adjusted to the specified column locations. If it is necessary to set more tab stops than specified in the tab-stop list, the tab character is replaced by one space.

  • Specify one tab stop location in the tab-stop list and specify the option multiple times.

  • Combine both of the above specification methods.

Tab stops are set for each input line from the first value specified. Specify tab stop locations in ascending order in the entire arguments.

path-name

Specifies the path name of the file in which tab characters are to be replaced with spaces. If no path name or - is specified, the path name is loaded from the standard input.

If multiple files are specified and one of the files results in an open error, the command issues an error message and continues processing.

Return codes

Return code

Meaning

0

Normal termination

1

Error termination

  • Path name contained a file that could not be opened.

2

Error termination (excluding the case resulting in termination code 1)

Notes

Examples

Specifying one tab stop location

If one tab stop is specified, the command uses the specified value as the character spacing between tab stops.

The following example specifies 6 for the tab stop for file file1:

Contents of file1

In the following file, [Figure] indicates the tab character.

----+----+----+----+----+----+-----
a001 [Figure] a002 [Figure] a003
b001 [Figure] b002    [Figure]    b003
c001 [Figure] c2   [Figure] c03
Command execution example

Specify 6 for the tab stop and file1 as the file:

$ expand -t 6 file1
Execution results
----+----+----+----+----+----+-----
a001  a002  a003
b001  b002        b003
c001  c2    c03

On the first line, tab stops are set at the specified interval of 6.

On the second line, two tab stops are set between b002 and b003 because there are two tab characters.

On the third line, c001, c2, and c03 that have different numbers of characters are set at a tab stop interval of 6.

Specifying multiple tab stop locations by using a tab-stop list

When multiple tab stops are specified, the tab stops are set in the order specified. If it is necessary to set more tab stops than specified in the tab-stop list, the tab character is replaced by one space.

Contents of file1

In the following file, [Figure] indicates the tab character.

----+----+----+----+----+----+-----
a001 [Figure] a002 [Figure] a003 [Figure] a004
Command execution example 1

Specify 6,16 as the tab-stop list and file file1:

$ expand -t 6,16 file1
Execution results 1
----+----+----+----+----+----+-----
a001  a002      a003 a004

Character strings are output with the specified number of spaces placed.

Because the first value specified is 6, the command first outputs a001, places spaces through column 6, then outputs a002.

Similarly, the command outputs a002, places spaces through column 16, then outputs a003.

Because there are no more values in the tab-stop list, the command places one space, and then outputs a004.

Command execution example 2

Specify 2,16 as the tab-stop list and file file1:

$ expand -t "2 16" file1
Execution result 2
----+----+----+----+----+----+-----
a001            a002 a003 a004

Because the first value specified is 2, the command outputs a001 and then attempts to place spaces through column 2, but the current location is already beyond column 2 because a001 has been output. Therefore, the command ignores value 2, places spaces through column 16, which is the next value specified, and then outputs a002.

Because there are no more values in the tab-stop list, the command places one space before each of the subsequent character strings.

Specifying multiple tab stops in options

There are several ways to specify multiple tab stops by combining [-t tab-stop list] and [-tab-stop list]. All the following examples specify 2 and 16 as the tab stops and their results are the same:

$ expand -t 2 -t 16 file1
$ expand -t 2 -16 file1
$ expand -2 -t 16 file1
$ expand -2 -16 file1
$ expand -t 2,16 file1
$ expand -2,16 file1
Entering the backspace character

If the tab character is followed by the backspace character, the tab's column width is reduced.

Contents of file1

In the following file, [Figure] indicates the tab character.

There is a backspace character (^H) immediately before a003:

----+----+----+----+----+----+-----
a001 [Figure] a002 [Figure] ^Ha003[Figure]a004
b001 [Figure] b002 [Figure] b003 [Figure] b004
Command execution example

Execute the command using default tab stop 8:

$ expand file1
Execution results
----+----+----+----+----+----+-----
a001    a002   a003     a004
b001    b002    b003    b004

Because there is a backspace character (^H) immediately before a003, the command saves the results during output processing. As a result, the output location of a003 is column 16, not column 17.

Input from the standard input

If no path name is specified or if - is specified, files are input from the standard input.

Contents of file1

In the following file, [Figure] indicates the tab character.

----+----+----+----+----+----+-----
a001 [Figure] a002 [Figure] a003 [Figure] a004
Command execution example

Input file1 from the standard input:

$ expand < file1

or

$ expand - < file1
Execution results
----+----+----+----+----+----+-----
a001    a002    a003    a004