mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
翻译完成
This commit is contained in:
parent
38d82260bb
commit
f73f698f17
@ -1,25 +1,24 @@
|
|||||||
(translating by runningwater)
|
Grep 命令统计匹配的字符串/单词行数
|
||||||
Grep Count Lines If a String / Word Matches
|
|
||||||
================================================================================
|
================================================================================
|
||||||
How do I count lines if given word or string matches for each input file under Linux or UNIX operating systems?
|
在 Linux 或 UNIX 操作系统下,对于给定的单词或字符串,我们应该怎么统计它们在每个输入文件中存在的行数呢?
|
||||||
|
|
||||||
You need to pass the -c or --count option to suppress normal output. It will display a count of matching lines for each input file:
|
您需要通过添加 -c 或者 --count 选项参数来抑制正常的输出。它将会显示对输入文件单词匹配的行数,如下示:
|
||||||
|
|
||||||
$ grep -c vivek /etc/passwd
|
$ grep -c vivek /etc/passwd
|
||||||
|
|
||||||
OR
|
或者
|
||||||
|
|
||||||
$ grep -w -c vivek /etc/passwd
|
$ grep -w -c vivek /etc/passwd
|
||||||
|
|
||||||
Sample outputs:
|
输出的示例:
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
||||||
However, with the -v or --invert-match option it will count non-matching lines, enter:
|
相反的,使用 -v 或者 --invert 选项参数可以统计出不匹配的输入文件行数,键入:
|
||||||
|
|
||||||
$ grep -c vivek /etc/passwd
|
$ grep -c vivek /etc/passwd
|
||||||
|
|
||||||
Sample outputs:
|
输出的示例:
|
||||||
|
|
||||||
45
|
45
|
||||||
|
|
Loading…
Reference in New Issue
Block a user