【发布时间】:2011-02-03 17:02:13
【问题描述】:
s 在那里是什么意思,当管道进入 wc 是什么意思?我知道它最终会计算文件文件名中出现的 abc 的数量,但不确定选项 s 和管道到 wc 的意思
linux command grep -is "abc" filename|wc -l
输出
47
【问题讨论】:
-
人会在一分钟内把你送到那里。
s 在那里是什么意思,当管道进入 wc 是什么意思?我知道它最终会计算文件文件名中出现的 abc 的数量,但不确定选项 s 和管道到 wc 的意思
linux command grep -is "abc" filename|wc -l
输出
47
【问题讨论】:
-s 表示“抑制有关不可读文件的错误消息”,而到 wc 的管道表示“获取输出并将其发送到 wc -l 命令”,它有效地计算匹配的行数。您可以使用 grep 的 -c 选项来完成相同的操作: grep -isc "abc" filename
【讨论】:
考虑一下,
command_1 | command_2
管道的作用是——它获取在它之前写的命令的输出(这里是command_1)并将该输出提供给它之后写的命令(这里是command_2)。
【讨论】:
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。
【讨论】:
wc,也许会更清楚一点。
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 它返回行数。
【讨论】: