当模式字符串中存在句号 (.) 时,agrep 会给出错误 agrep:pattern too long (has > 32 chars)
,但其他情况下则不会。
我想比较(大约)两个字符串,因此我使用 agrep 来进行比较,但它给出了错误 agrep:pattern too long (has > 32 chars)
。但我发现如果模式字符串中没有句号,它不会给出错误(为什么?)
`echo "The quick brown fox jumped over the lazy dog." | agrep -c -4 "The quick brown fox jumped over the lazy dog."`
预期输出是 1,但它给出了错误:
agrep:模式太长(超过 32 个字符)
如果我删除句号,它就会起作用:
$ echo "The quick brown fox jumped over the lazy dog." | agrep -c -4 "The quick brown fox jumped over the lazy dog"
1
最佳答案
使用两个字符串进行近似字符串匹配/模糊字符串搜索。
使用agrep
和bash
:
if agrep -1 "abc" <<< "xbc" >/dev/null; then echo "match"; else echo "no match"; fi
或者使用tre-agrep
和bash
:
if tre-agrep -q -1 "abc" <<< "xbc"; then echo "match"; else echo "no match"; fi
两种情况下的输出:
match
关于bash - 如何修复错误 agrep : pattern too long (has > 32 chars) it doesn't show error if there is no full stop in the string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57533885/