unexpand Command Examples in Linux

This tutorial explains Linux “unexpand” command, options and its usage with examples.

unexpand – convert spaces to tabs

Description :

Convert spaces in each FILE to tabs, writing to standard output. With no FILE, or when FILE is -, read standard input.

Usage :

unexpand [OPTION]… [FILE]…

advertisement
advertisement

Options :

-a, –all
convert all blanks, instead of just initial blanks.
–first-only
convert only leading sequences of blanks (overrides -a).
-t, –tabs=N
set tabs N characters apart instead of the default of 8 (enables -a).
-t, –tabs=LIST
use comma separated LIST of tab positions (enables -a).

Examples :

Note: Join free Sanfoundry classes at Telegram or Youtube

1. Basic Example

$ cat -vet file2
One     Two     Three   Four    Five    six     seven$
One     Two     Three   Four    Five    six     seven$
One     Two     Three   Four    Five    six     seven$
One     Two     Three   Four    Five    six     seven$
One     Two     Three   Four    Five    six     seven$
One     Two     Three   Four    Five    six     seven$
One     Two     Three   Four    Five    six     seven$
One     Two     Three   Four    Five    six     seven$

By using the “cat -vet” option against file1, we can see that the tabs are represented by the “I^” character.The “$” denotes a line feed.

advertisement
$ unexpand -a file2 > file3
$ cat -vet file3
One^ITwo^IThree^IFour^IFive^Isix^Iseven$
One^ITwo^IThree^IFour^IFive^Isix^Iseven$
One^ITwo^IThree^IFour^IFive^Isix^Iseven$
One^ITwo^IThree^IFour^IFive^Isix^Iseven$
One^ITwo^IThree^IFour^IFive^Isix^Iseven$
One^ITwo^IThree^IFour^IFive^Isix^Iseven$
One^ITwo^IThree^IFour^IFive^Isix^Iseven$
One^ITwo^IThree^IFour^IFive^Isix^Iseven$

Hece the spaces are converted into tabs.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

advertisement
If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.