Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Unix expand/unexpand commands

News Syntax Recommended Links Sorting algorithms Recommended Papers Rcut Reference Pipes
Perl re-implemenations uniq sort tr AWK Tips Humor Etc

The external expand command expands tabs to spaces. The expand command reads the named files or the standard input, changes the tabs to the appropriate number of blanks, and writes the results on the standard output.

You use the expand command to convert tab characters to the appropriate number of spaces. You may find expand useful to preprocess character files that contain tabs before performing character processing on the files. For example, you may want to remove tabs before sorting or examining specific columns of a file.

The external unexpand command replaces leading spaces and tabs with just tabs where possible.

Following is the general format of the expand command.

     expand   [ -tabstop | -tab1,tab2,tab3,...,tabn ] [ file_list ]
     unexpand [ -a ] [ file_list ]

Options

The following options may be used to control how expand functions.

-tabstop Sets tab stops tabstop spaces apart.
-tab1,.,tabn Sets tabs at specific tab positions defined by tab1 through tabn.
-a Tabs are inserted at all occurrences that would replace two or more spaces. Without the -a option unexpand only replaces leading blanks and tabs.

Arguments

The following argument may be passed to the expand command.

file_list The list of files read and processed by expand. If no files are specified expand reads the standard input.

 

 

Examples

In this activity you use the expand command to remove tabs from a file containing tab-separated columns. Begin at the shell prompt.

1.  Type cat -v -t file1 and press Return. Notice the ^I (tabs) embedded in the output.
2.  Type expand file1 | cat -v -t and press Return. Notice the output has no tabs in it.
3.  Turn to Module 143 to continue the learning sequence.

Copyright © 1996-2007 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: March 15, 2008