Let me briefly introduce
The function of the WC (Word Count) command is to count the number of bytes, words, and rows in the specified file and display the statistics to output
Format: WC file
Command parameters:
-C counts the number of bytes (bytes) and displays the file name
-L Statistic line number: Use newline character ' \ n ' as line end flag, actually count the number of line breaks
-M statistics the number of characters. This flag cannot be used with the-C flag.
-W counts the number of words. A word is defined as a string delimited by a blank, jump, or newline character.
-L Prints the length of the longest line.
-HELP Display Help information
--version Display version Information
Example:
WC test.txt
6 132test.txt
Default output: line, Word, number of bytes
Test.txt content
Cat Test.txt
Test1 name1 Age1 sex1
Test2 name2 Age2 Sex2
Test3 Name3 Age3 sex3
Test4 name4 age4 sex4
Test5 name5 Age5 sex5
Test6 Name6 Age6 sex6
problem: The number of WC statistics is less than one line:
Because Wc–l is the number of rows to be counted as the line terminator, the last line will be lost if it is not \ nthe.
Example: For example, generate the same file Testtt.txt as above test.txt under Windows, and upload it to Linux:
Cat Testtt.txt
Test1 name1 Age1 sex1
Test2 name2 Age2 Sex2
Test3 Name3 Age3 sex3
Test4 name4 age4 sex4
Test5 name5 Age5 sex5
Test6 name6 Age6 sex6[wizad@srv26 lmj]$
You can see that the ending is a little strange. This is because the file is not at the end of \ n, but is used directly by the file Terminator EOF. This file uses WC statistics for a smaller line:
Wc-l Testtt.txt
5 136 Testtt.txt
You can't use a pipe either:
Cat Testtt.txt | Wc-l
5
Why there is no such problem under Linux.
Because the Vim editor automatically adds \ n to the end of the file, EOF is added to the file terminator. (Linux text files are mainly processed, so vim will be the last line automatically added \ n)
It is not possible to convert Windows files with Dos2unix:
[Wizad@srv26 lmj]$ Dos2unix Testtt.txt
dos2unix:converting file testtt.txt Tounix format ...
[Wizad@srv26 lmj]$ WC testtt.txt
5 24131 Testtt.txt
You can see that Windows files have compatibility issues under Linux. The number of words in the file is not changed 24,byte 5 is a Windows down terminator is a carriage return \r+ newline \ n. And Linux is just wrapping.
Vim binary can see different, \ n shows as., no end of file