a brief introduction to WC
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.
Two 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)
three use examplesExample One[Email protected] ~]# wc/etc/passwd 2027/etc/passwdNumber of rows Word count bytes file name
[[email protected] ~]# wc-l/etc/passwd &NBSP;
46/etc/passwd
[[email protected] ~]# wc-cmlwl/etc/passwd
46 66 2027 2027 74/ETC/PASSWD
[[email protected] ~]# WC-CMLLW/ ETC/PASSWD
46 66 2027 2027 74/etc/passwd
[[email protected] ~]# WC-WCMLL/ETC/PASSWD&NBSP; BR clear= "None" > 46 66 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
Using pipe lines, which 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. UTF-8
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] ~]# Cattest1
Hello China
Linux
[Email protected] ~]# WC test1
2 2 Test1
Number of rows Word count bytes file name