In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "case analysis of the use of fold commands". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The fold command is used to limit the file column width, which reads the contents from the specified file, adds additional characters to the columns that exceed the limited column width, and outputs them to the standard output device. If no file name is specified, or if the file name given is -, the fold command reads data from the standard input device.
Sample tutorial for fold commands
The fold command is part of the GNU coreutils package, so we don't have to worry about the installation. Typical syntax for the fold command:
Fold [OPTION]... [FILE]...
Allow me to show you some examples so that you can better understand the fold command. I have a file called linux.txt, which is random. To change the default width of each line in the above file, run:
Fold linux.txt
80 columns per row is the default width. Here is the output of the above command: as you can see in the output above, the fold command has limited the output to a width of 80 characters. Of course, we can specify your preferred width, such as 50, as follows:
Fold-w50 linux.txt
Sample output: we can also write the output to a new file, as shown below:
Fold-w50 linux.txt > linux1.txt
The above command changes the line width of linux.txt to 50 characters and writes the output to a new file called linux1.txt. Let's check the contents of the new file:
Cat linux1.txt
Have you noticed the output of the previous command? Some words are interrupted between lines. To solve this problem, we can use the-s flag to wrap lines in the space. The following command adjusts each line in a given file to a width of 50 and changes to a new line at the space:
Fold-W50-s linux.txt
Did you get a good look? Now, the output is clear. The words in the new line are separated by spaces, and when the length of the word in the new line is greater than 50, it will be adjusted to the next line. In all the above examples, we use columns to limit the width of the output. However, we can use the-b option to force the width of the output to the specified number of bytes. The following command interrupts the output with 20 bytes.
This is the end of the fold-b20 linux.txt "fold Command usage case Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.