Linux WC Command Application examples

Source: Internet
Author: User

The WC is used for counting under Linux. Returns the number of rows, words, bytes, and so on in the file.

For example:

The code is as follows:

WC Wc1.txt

3 5 Wc1.txt

Output information in order: number of rows number of bytes file name. More specifically, a single statistic.

Copy Code

The code is as follows:

#wc-M FileName: Number of characters displayed for a file

#wc-L FileName: Displays the number of rows in a file

#wc-L FileName: Displays the length of the longest line in a file

#wc-W FileName: Displays the number of words in a file

Note: The seemingly WC statistics are determined by line breaks. This means that the last line has a newline character, the last WC row number is correct, otherwise there will be fewer lines.

To illustrate this issue, look at a Perl test:

The code is as follows:

Perl-e ' print ' a ' |WC

0 1 1

Perl-e ' print ' an ' |WC

1 1 2

In the example above, the Print command prints a, and if you do not have a newline character N, you don't think the line exists.

Description

1: A Chinese character for three bytes (unauthenticated, personally considered to be two bytes), a carriage return and other invisible characters also occupy a byte

2: At the end of a line if there is no carriage return, is not a row, that is, if a file has no newline at the end of the last line, the WC command counts fewer rows than the actual number of rows, and the actual number of rows is the number of rows you see, in fact, there is no carriage return, it does not count as a line ( Note: If in an existing text, the default is to have an invisible carriage return for all rows.

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.