use*_*935 4 grep sed text-processing
每当找到FW_6.0.0时,我的命令都会打印出两行,下面是代码:
grep -oP 'FW_6.0.0, (.*)$' file
Run Code Online (Sandbox Code Playgroud)
下面是输出,两者都具有相同的FW_6.0.0值
FW_6.0.0, SUCCESS
FW_6.0.0, OK
Run Code Online (Sandbox Code Playgroud)
我想匹配两个词,即FW_6.0.0和SUCCESS可以在同一行找到,以便打印出来:
FW_6.0.0, SUCCESS 并消除 FW_6.0.0, OK
尝试使用双引号"":
grep -oP "FW_6.0.0, SUCCESS" file
Run Code Online (Sandbox Code Playgroud)
OR(因为它是一个固定字符串,而不是一个模式):
grep -oF "FW_6.0.0, SUCCESS" file
Run Code Online (Sandbox Code Playgroud)
来自 grep 手册页:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched. (-F is specified by
POSIX.)
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression. This is highly
experimental and grep -P may warn of unimplemented features.
Run Code Online (Sandbox Code Playgroud)