In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge of this article "linux how to count the number of lines in a file", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "linux how to count the document how many lines" article.
In linux, you can use the wc command to count how many lines there are in the file. The function of this command is to count the number of bytes, words and lines in the specified file, and display the output of the statistical results. When the parameter is set to "- l", the number of lines in the file will be counted. The syntax is "wc-l file name".
This article operating environment: linux7.3 system, Dell G3 computer.
How does linux count the number of lines in a file?
Using the wc instruction, we can calculate the number of Byte, words, or columns of a file, count the number of bytes, words and lines in a specified file, and display the statistical results to output.
The syntax is:
Wc [options] file.
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.
Examples are as follows:
Count the number of lines, words and bytes of files
$wc test.txt 1 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 above is about the content of this article on "how to count the number of lines in the linux document". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
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.