可能这是新手问题,但我必须问!
一般来说,我理解正则表达式,但我不明白,为什么这个:
^.{8}[[:blank:]]{2}
在这条线上工作:
prelink: /lib/libkeyutils-1.2.so: at least one of file's dependencies has changed since prelinking
在这个 grep 命令中:
echo "prelink: /lib/libkeyutils-1.2.so: at least one of file's dependencies has changed since prelinking" | grep -v '^.\{8\}[[:blank:]]\{2\}'
哪里:
The says "beggining of line" The .{8} says "any eight characters" The [[:blank:]]{2} says "any two space characters"
So ^.{8} match "prelink:", when [[:blank:]]{2} need matching " " (two spaces), but we have only " " (one space)... So why this work at all, and if this work why this one:
^.{8}[[:blank:]]{1}
不起作用?
谢谢你提前。
最佳答案
您正在使用 grep
和 -v
选项,这导致它打印不匹配的行。删除 -v
,它将按您预期的那样工作。
grep --help ... -v, --invert-match select non-matching lines ...
关于regex - 正则表达式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3461584/