The WC command is used to print the number of lines of text, number of words, number of bytes, and so on (print the newlines, words, and bytes in files). In Windows Word has a "word count" tool, you can help us to the selected range of words, characters count out. The WC command under Linux can implement this function. When using VI to open a file, the information below will also show the number of rows and bytes.
Common parameters
Format: Wc-l <file>
Prints the number of lines of text for the specified file. (l= lowercase L)
The following parameters can be used in combination.
Parameters:-C,--bytes
Number of bytes printed (print the byte counts)
Parameters:-M,--chars
Number of characters printed (print the character counts)
Parameter:-L,--lines
Print the number of lines (print the newline counts)
Parameter:-L,--max-line-length
Print the length of the longest line (print the length of the longest lines)
Parameters:-W,--words
Print the number of words (print the word counts)
Using the example
Example One
[Email protected] ~]# WC/ETC/PASSWD
2027/etc/passwd
Number of Rows Word count bytes file name
[Email protected] ~]#
[Email protected] ~]# wc-l/etc/passwd
46/etc/passwd
[Email protected] ~]# WC-CMLWL/ETC/PASSWD
2027 2027 74/ETC/PASSWD
[Email protected] ~]# WC-CMLLW/ETC/PASSWD
2027 2027 74/ETC/PASSWD
[Email protected] ~]# WC-WCMLL/ETC/PASSWD
2027 2027 74/ETC/PASSWD
[Email protected] ~]#
Here's the problem: from the command line above, the order of the WC output data seems to have nothing to do with the order of several parameters.
Example two with WC command How do I print statistics without printing file names
Use pipe lines. This is especially useful when writing shell scripts.
[Email protected] ~]# wc-l/etc/passwd
46/etc/passwd
[Email protected] ~]# CAT/ETC/PASSWD | Wc-l
46
[Email protected] ~]#
An example of three Chinese coding problems
The execution environment is encoded in Chinese.
[Email protected] ~]# echo $LANG
Zh_cn. GB18030
Chinese encoded file Ehr_object.gv,utf8 encoded file EHR_OBJECT_UTF8.GV.
[Email protected] ~]# file EHR_OBJECT.GV EHR_OBJECT_UTF8.GV
ehr_object.gv:iso-8859 text
Ehr_object_utf8.gv:utf-8 Unicode Text
[Email protected] ~]#
[Email protected] ~]# WC EHR_OBJECT.GV EHR_OBJECT_UTF8.GV
830 EHR_OBJECT.GV
Wc:ehr_object_utf8.gv:4: invalid or incomplete multibyte character or wide character
866 EHR_OBJECT_UTF8.GV
22 210 1696 Total
[Email protected] ~]#
Example four Chinese word count calculation
[email protected] ~]# cat Test.txt
Hello Word
Linux
[Email protected] ~]# WC test.txt
3 2 Test.txt
Number of Rows Word count bytes file name
Example four print out the order according to the requirements change
WC-LC test.txt |awk ' {print $ "" $ $ "" $ ">> test2.txt
Shell Script WC command Detailed!! Demand output result