agrep gives the error agrep: pattern too long (has > 32 chars) when there is a full stop(.) in the pattern string but not otherwise.

I want to compare(approximately) two strings, so I'm using agrep for that but its giving an error agrep: pattern too long (has > 32 chars) . But I found out that it doesn't give the error if there is no full stop in the pattern string(why?)

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

expected output is 1 instead it gives an error: agrep: pattern too long (has > 32 chars)

it works if I remove the full stop:

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

There are 3 best solutions below

5
Cyrus On

Approximate string matching / fuzzy string searching with two strings.

With agrep and bash:

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

or with tre-agrep and bash:

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

Output in both cases:

match
0
desgua On

The problem is that agrep is treating . as a meta character. To avoid that you must pass the option -k:

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

The man page on agrep says:

-k No symbol in the pattern is treated as a meta character.

0
user1986384 On

The limit of 32 characters has to do with the register width it is optimized for: 32 bit. See #define WORD 32 in agrep.h.

Switch to 64 bit seems to be more work than changing unsigned to unsigned long and doubling constants in agrep.h.