"string matching" 和 "pattern matching" 之间的区别
Difference between "string matching" and "pattern matching"
fgrep 命令不同于 grep 和 egrep 命令,因为它搜索字符串而不是搜索与表达式匹配的模式。
有人可以用一个简单的例子解释一下使用上的区别吗?
fgrep
等同于grep -F
,egrep
等同于grep -E
grep -F
匹配字符串,grep -E
匹配扩展正则表达式。
给定输入文件:
$ cat file
Hello Alice!
Hello Bob!
Hi Alice!!
Hi Bob!!
模式匹配:
$ grep -E -f <(echo -e "Ali.*\nBob") file
Hello Alice!
Hello Bob!
Hi Alice!!
Hi Bob!!
字符串匹配:
$ grep -F -f <(echo -e "Ali.*\nBob") file
Hello Bob!
Hi Bob!!
在第二个示例中,Ali.*
与 Alice
不匹配,因为 grep
将其视为乱码字符串。
我建议看看 this page。
fgrep 命令不同于 grep 和 egrep 命令,因为它搜索字符串而不是搜索与表达式匹配的模式。
有人可以用一个简单的例子解释一下使用上的区别吗?
fgrep
等同于grep -F
,egrep
等同于grep -E
grep -F
匹配字符串,grep -E
匹配扩展正则表达式。
给定输入文件:
$ cat file
Hello Alice!
Hello Bob!
Hi Alice!!
Hi Bob!!
模式匹配:
$ grep -E -f <(echo -e "Ali.*\nBob") file
Hello Alice!
Hello Bob!
Hi Alice!!
Hi Bob!!
字符串匹配:
$ grep -F -f <(echo -e "Ali.*\nBob") file
Hello Bob!
Hi Bob!!
在第二个示例中,Ali.*
与 Alice
不匹配,因为 grep
将其视为乱码字符串。
我建议看看 this page。