CentOS row counting method and efficiency test

Source: Internet
Author: User
Note: Blue = command name light green = command parameter light blue = Option purple = directory system environment: Cent

Note: Blue = command name

Light green = command parameters

Light blue = Option

Purple = Directory

System environment: CentOS 6.2 i686

I. statistics on the number of rows

1. system commands:Wc-l filename

2. grep method:Grep-c "" filename

3. sed method:Sed-n' $ = 'filename'

4. awk method:Awk 'end {print NR} 'filename

II. efficiency testing

Generate the required test File: awk 'In in {for (I = 0; I <10000000; I ++) print I} '> test

Note: the methods described in this article are used to perform three tests on the test file and calculate the time. the average value is used for comparison.

1. wc method: time wc-l test

Time:0.234 s 0.242 s 0.237 s

Average:0.237667 s

2. grep method:Time grep-c "" test

Time:1.503 s 1.340 s 1.414 s

Average:1.419000 s

3. sed method: time sed-n' $ = 'Test

Time:2.268 s 2.258 s 2.344 s

Average:2.290000 s

4. awk method: time awk 'end {print NR} 'test

Time:1.637 s 1.638 s 1.649 s

Average:1.641330 s

 

Summary:

Wc is much more efficient than other methods. efficiency: wc> grep> awk> sed

 

Supplement: wc usage

Syntax: wc [option] file

Note: this command counts the number of bytes, number of words, and number of lines in a given file. If no file name is provided, it is read from the standard input. Wc also provides the president count for all specified files. Is the largest string separated by space characters.

The options of this command are as follows:

-C: counts the number of bytes.

-L number of statistics rows.

-W counts the number of words.

These options can be used in combination

This article is from the "left_left" blog, please be sure to keep this source http://linux521.blog.51cto.com/4099846/767860

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.