What I am trying to do is to get the best-matching word in a file and the number of errors for it using agrep
. For now I am only able to get the word using this script:
array=(bla1 bla2 bla3)
for eachWord in "${array[@]}"; do
result=$(yes "yes" | agrep -B ${eachWord} /home/victoria/file.txt)
printf "$result\n"
done
Where bla{1,2,3} are some words.
The output I have is the following:
agrep: 4 words match within 2 errors; search for them? (y/n)counting
first
and
should
agrep: 1 word matches within 1 error; search for it? (y/n)should
agrep: 2 words match within 4 errors; search for them? (y/n)must
must
agrep: 1 word matches within 2 errors; search for it? (y/n)should
Is there any way I can have the number of errors (2,1,4,2 in the output example above)?