Text Transforms
Reshape data between columns and rows — paste -sd, for collapsing, tr for expanding, awk for complex transforms.
paste — Column to Row
The primary use: collapse a column of values into a single comma-separated row.
paste -sd, /tmp/vlans.txt
# → 144,146,621,721,1551,1651,1921
-s = serial (concatenate all lines into one). -d, = delimiter is comma.
-s, paste merges columns from multiple filespaste file1.txt file2.txt # Side-by-side columns (tab-delimited)
paste -d, file1.txt file2.txt # Comma-delimited columns
The -s flag changes the axis: without it, paste works horizontally across files. With it, paste works vertically within a single file.
Network Engineering Pipeline
The real-world pattern: extract VLANs from switch output → collapse into trunk allowed-list format.
# From a file
awk 'NR>2 && /^[0-9]+/{print $1}' show-vlan-brief.txt | paste -sd,
# → 144,146,621,721,1551,1651,1921
# From an SSH session (no temp file)
ssh admin@switch "show vlan brief" \
| awk 'NR>2 && /^[0-9]+/{print $1}' \
| paste -sd,
VLANS=$(ssh admin@switch "show vlan brief" | awk 'NR>2 && /^[0-9]+/{print $1}' | paste -sd,)
echo "switchport trunk allowed vlan ${VLANS}"
Alternatives Compared
| Tool | Command | Trailing Delimiter? |
|---|---|---|
|
|
No ✅ |
|
|
Yes ❌ (trailing comma) |
|
|
No ✅ (verbose) |
|
|
No ✅ (verbose) |
paste -sd, wins: no trailing delimiter, no printf gymnastics, one command.
Row to Column (Reverse)
echo "144,146,621,721,1551,1651,1921" | tr ',' '\n'
echo "144,146,621,721,1551,1651,1921" | awk -F, '{for(i=1;i<=NF;i++) print $i}'
Other paste Patterns
paste <(seq $(wc -l < file.txt)) file.txt
paste -d'\n' questions.txt answers.txt
paste -d= keys.txt values.txt
paste - - < file.txt
# Three per row:
paste - - - < file.txt
Delimiter Variations
paste -sd';' file.txt
paste -sd' ' file.txt
paste -sd'|' patterns.txt
# → pattern1|pattern2|pattern3 (ready for grep -E)