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