2

当模式字符串中有句点(。)时, 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: 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
4

2 回答 2

2

使用两个字符串进行近似字符串匹配/模糊字符串搜索。

agrepbash:_

if agrep -1 "abc" <<< "xbc" >/dev/null; then echo "match"; else echo "no match"; fi

tre-agrepbash

if tre-agrep -q -1 "abc" <<< "xbc"; then echo "match"; else echo "no match"; fi

两种情况下的输出:

匹配
于 2019-08-17T08:35:24.497 回答
0

问题在于agrep.其视为元字符。为避免这种情况,您必须通过选项-k

echo "The quick brown fox jumped over the lazy dog." | agrep -c -4 -k "The quick brown fox jumped over the lazy dog."

agrep 上的手册页说:

-k 模式中没有符号被视为元字符。

于 2020-12-12T21:03:16.400 回答