Previous: , Up: Operating on characters   [Contents][Index]

9.3 unexpand: Convert spaces to tabs

unexpand writes the contents of each given file, or standard input if none are given or for a file of ‘-’, to standard output, converting blanks at the beginning of each line into as many tab characters as needed. In the default POSIX locale, a blank is a space or a tab; other locales may specify additional blank characters. Synopsis:

unexpand [option]… [file]…

By default, unexpand converts only initial blanks (those that precede all non-blank characters) on each line. It preserves backspace characters in the output; they decrement the column count for tab calculations. By default, tabs are set at every 8th column.

The program accepts the following options. Also see Common options.

-t tab1[,tab2]…

If only one tab stop is given, set the tabs tab1 columns apart instead of the default 8. Otherwise, set the tabs at columns tab1, tab2, … (numbered from 0), and leave blanks beyond the tab stops given unchanged. Tab stops can be separated by blanks as well as by commas. This option implies the -a option.

For compatibility, GNU unexpand supports the obsolete option syntax, -tab1[,tab2]…, where tab stops must be separated by commas. (Unlike -t, this obsolete option does not imply -a.) New scripts should use --first-only -t tab1[,tab2]… instead.


Also convert all sequences of two or more blanks just before a tab stop, even if they occur after non-blank characters in a line.

An exit status of zero indicates success, and a nonzero value indicates failure.

Previous: , Up: Operating on characters   [Contents][Index]