LINUX-WC the number of rows, words, or bytes of a statistic file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.