expand
Quick Reference
Command Name:
expand
Category:
text processing
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Tab expansion
Convert tabs to spaces in text data
- 2
Text processing
Manipulate text data in pipelines and scripts
- 3
Data cleaning
Clean and sanitize text data
- 4
Scripting
Use in shell scripts to process text data programmatically
Syntax
expand [OPTION]... [FILE]...
Options
| Option | Description |
|---|---|
| -i, --initial | Only convert tabs at the beginning of lines. Tabs elsewhere in the line remain unchanged. |
| -t N, --tabs=N | Set tab stops to every N columns instead of the default 8. This determines how many spaces replace each tab. |
| -t LIST, --tabs=LIST | Use a comma-separated list of tab positions (e.g., 2,4,8). Each number specifies a column position for a tab stop. |
| --help | Display help information and exit. |
| --version | Output version information and exit. |
Examples
How to Use These Examples
The examples below show common ways to use the expand command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
expand file_with_tabs.txt
Converts all tabs in the file to spaces (using the default 8-space tab stops) and outputs the result to standard output.
expand -t 4 file_with_tabs.txt
Converts tabs to 4 spaces instead of the default 8. This is useful when working with code that uses 4-space indentation.
expand -t 4 file_with_tabs.txt > file_with_spaces.txt
Converts tabs to 4 spaces and saves the result to a new file instead of displaying it on screen.
cat file_with_tabs.txt | expand -t 2
Reads input from a pipe instead of a file, converting all tabs to 2 spaces. This demonstrates how expand can work within command pipelines.
Advanced Examples:
expand -i file_with_tabs.txt
Only convert initial tabs on each line to spaces, preserving any tabs that occur after non-whitespace characters. This is useful for files where tabs are used for both indentation and data alignment.
expand -t 4,8,12,16 file_with_tabs.txt
Sets custom tab stops at columns 4, 8, 12, and 16. This gives precise control over how tabs are converted, which can be useful for preserving alignment in structured text files.