In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the expand and unexpand commands in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Example of expand command
As I mentioned earlier, the expand command replaces TAB characters in the file with spaces.
Now, let's convert the TAB in ostechnix.txt to spaces and write the result to standard output:
$expand ostechnix.txt
If you don't want to display the results in standard output, just write it to another file, as shown below.
$expand ostechnix.txt > output.txt
We can also convert TAB in standard input to spaces. To do this, simply run the expand command without the file name:
$expand
Simply type the text and press enter to convert TAB to spaces. Press CTRL+C to exit.
If you do not want to convert TAB after non-white space characters, use the-I flag, as shown below.
$expand-I ostechnix.txt
We can also set each TAB to the width of the specified number instead of 8 (the default).
$expand-tasking 5 ostechnix.txt
We can even specify multiple TAB locations separated by commas, as shown below.
$expand-t 5je 10je 15 ostechnix.txt
Or
$expand-t "5 10 15" ostechnix.txt
For more details, see the man pages.
Example of the $man expandunexpand command
As you may have guessed, the unexpand command does the opposite of the expand command. That is, it converts spaces to TAB. Let me show you some examples of how to use the unexpand command.
To convert white space (spaces, of course) in a file to TAB and write the output to standard output:
$unexpand ostechnix.txt
If you want to write the output to a file instead of just displaying it to standard output, use the following command:
$unexpand ostechnix.txt > output.txt
Read from standard output and convert spaces to tabs:
$unexpand
By default, the unexpand command converts only the initial spaces. If you want to convert all spaces instead of just spaces at the beginning of a line, use the-a flag:
$unexpand-an ostechnix.txt
Convert only the spaces at the beginning of the line (note that it overrides-a):
$unexpand-first-only ostechnix.txt
Replace how many spaces with a TAB instead of 8 (- an is enabled):
$unexpand-t 5 ostechnix.txt
Similarly, we can specify multiple TAB locations separated by commas.
$unexpand-t 5je 10je 15 ostechnix.txt
Or
$unexpand-t "5 10 15" ostechnix.txt
For more details, see the man pages.
$man unexpand
The expand and unexpand commands are useful for replacing unwanted TAB with spaces when working with a large number of files, and vice versa.
Thank you for reading! This is the end of the article on "how to use expand and unexpand commands in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.