expand

Convert tabs to spaces (POSIX)

Syntax:

expand [-t tablist] [file...]

Runs on:

Neutrino

Options:

-t tablist
Set up tab stops according to the tablist argument. This argument consists either of a single positive decimal integer, or of multiple positive decimal integers, in ascending order, separated by single commas.

If no number is given, tabs stops are set eight columns apart. If a single number is given, tab stops are set tablist columns apart. If multiple numbers are given, tab stops are set at those columns.

file
The pathname of a file whose tabs are to be converted.

Description:

The expand utility copies files or the standard input to the standard output with tab characters replaced by the number of spaces needed to pad to the next tab stop. Any backspace characters encountered in the input are copied to the output and cause the column position count for the tab-stop calculations to be decremented; the count is never decremented below zero.

The -t option lets you specify how many columns tab stops are set apart. You can also use it to specify a multiple tab-stop list that determines where tab stops are placed. If tab characters are present in the input past the last tab stop specified in a multiple tab-stop list, those tabs are each replaced by a single space in the output.

Note that tabbing to position N causes the next character written to appear in the next column position on that line (i.e. column N+1)

Examples:

For the file myfile, expand each tab to the number of spaces required to reach the next tab stop:

expand myfile

Do the same as above, except set tab stops to every four columns rather than the default eight:

expand -t4 myfile

Place tab stops at the specified columns. Any tab encountered past the last tab stop is replaced by a single space:

expand -t8,12,20,24,32,36,44,48 myfile

Exit status:

0
Successful completion.
>0
An error occurred.

Caveats:

The expand utility doesn't check to verify that the tab stops specified in the -t option are in ascending order, as is required for proper operation.