In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the Linux counter WC command, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The Linux wc command is used to calculate the word count. Using the wc instruction, we can calculate the number of Byte, words, or columns of a file. If the file name is not specified, or the file name given is "-", the wc instruction will read the data from the standard input device.
Main parameters
Common parameters are as follows:
C counts the number of bytes. -l count the number of rows. -m counts the number of characters. This flag cannot be used with the-c flag. -w count the word count. Note that the words here refer to strings separated by spaces, newline characters, and so on.
Let's go straight to a few examples.
Count file lines, words and bytes $wc test.txt1 1 7 test.txt
The print results show that the file has 1 line, 1 word, and 7 bytes.
In particular, the words here are strings separated by spaces, newline characters, etc., that is to say,
Words words
There are only two words here.
Count only the number of lines, words, characters or bytes of files
When you only count individual items, you only need to take the corresponding parameters, for example:
$wc-l test.txt1 test.txt
Use the-l argument so that only the number of rows is displayed.
However, special attention should be paid to the difference between the number of characters and the number of bytes. The number of bytes is the amount of space occupied by the data, while a character may take up more than one byte. For example, in UTF-8 encoding, an English letter is a character that takes up one byte of space, while a Chinese character takes up 3 bytes.
For example:
Programming
Programming, in this case, is two characters, and the footprint is 6 bytes, but using wc-m statistics will be one more than two, which is three characters.
$echo programming | wc-m3 $echo programming | wc-c7
The occupation of each encoded character is as follows:
Encode English letter Chinese UTF-81 byte 3 bytes Unicode1 byte 2 bytes
You can use:
$echo $LANGen_GB.UTF-8
View the encoding format.
Count the number of command execution results
In fact, I think that the most commonly used parameter is the-l parameter, which is used to count the number of lines in a file or standard output, so it can actually be used to do a lot of statistical things.
For example, count how many ordinary files are in the current directory:
$ls-ltotal 4Mar RWMub RWMAY-1 hyb hyb 0 March 21 20:32 test2.txt-rw-rw-r-- 1 hyb hyb 13 March 21 20:18 test.txt$ ls-l | grep "^ -" | wc-L2
The number of files you can get is 2. Grep "^ -" means to get which lines start with -, because normal files start with -.
Of course, if you want to count the total number of files including subdirectories, you can add the-R parameter:
Ls-lR | grep "^ -" | wc-l
For example, check the number of chrome-related processes:
$ps-ef | grep google | grep-v grep | wc-L23
There are many similar uses, as long as you want to do statistics.
Here are a few more words:
| ls-l | wc-l means to pass the result of ls-l to wc command processing grep for text lookup, grep "a" to find lines containing a, and grep-v "b" to filter rows containing b. Thank you for reading this article carefully. I hope the article "how to use Linux counter WC commands" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.