bash - 如何修复错误 agrep : pattern too long (has > 32 chars) it doesn't show error if there is no full stop in the string?

标签 bash agrep

当模式字符串中存在句号 (.) 时,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

最佳答案

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

使用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

两种情况下的输出:

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/

相关文章:

file - SFTP 使用 bash 脚本发送文件

linux - 更快的方式来agrep?快速找到每个不匹配的字符

mysql - SQL:匹配字符串模式而不考虑大小写,列中的空格

bash - `shopt -s lastpipe` 如何影响 bash 脚本行为?

java - 为什么这个 Java 代码打印两个参数?

php - PHP中的多个关键字(100s到1000s)搜索(字符串搜索算法)

r - 与 R 中的 max.distance 相关的意外 agrep() 结果

linux - 使用文件名保存 zip 文件作为压缩文件的名称

bash - 在 Bash 循环中设置变量