繁体   English   中英

linux命令grep -is“ abc” filename | wc -l

[英]linux command grep -is “abc” filename|wc -l

那里的s是什么意思,当插入wc时又是什么意思? 我知道它最终会计算文件名中出现的abc数量,但不确定选项s以及管道到wc的意思

linux command grep -is "abc" filename|wc -l

输出

    47

考虑,

command_1 | command_2

管道的作用是-接收在其之前编写的命令的输出(此处为command_1),并将该输出提供给在其之后编写的命令(此处为command_2)。

-s表示“抑制有关不可读文件的错误消息”,而到wc的管道表示“获取输出并将其发送给wc -l命令”,该命令有效地计算了匹配的行数。 您可以使用grep的-c选项完成相同的操作:grep -isc“ abc” filename

man页包含有关grep选项的所有信息:

   -s, --no-messages
          Suppress  error  messages about nonexistent or unreadable files.
          Portability note: unlike GNU grep, traditional grep did not con-
          form to POSIX.2, because traditional grep lacked a -q option and
          its -s option behaved like GNU grep's -q option.  Shell  scripts
          intended to be portable to traditional grep should avoid both -q
          and -s and should redirect output to /dev/null instead.

wc -l的管道为您提供了字符串“ abc”出现在多少行的计数。 该字符串不一定出现在文件中的次数,因为多次出现的一行将仅计为1。

grep手册页说:

-s, --no-messages         suppress error messages

grep返回其中包含abc (不区分大小写)的行。 您通过管道将它们传送到wc以获得行数的计数。

来自man grep

  -s, --no-messages Suppress error messages about nonexistent or unreadable files. 

wc命令计算行,单词和字符。 用-l返回行数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM