Under macOS or Linux it is pretty easy. Create this bash script and make it executable:
Code:
#!/bin/bash
PAT=${1:?"Usage: grep-epub PAT *.epub files to grep"}
shift
: ${1:?"Need epub files to grep"}
for i in $* ;do
echo $0 $i
unzip -p $i "*.htm*" "*.xml" "*.opf" |
perl -lpe 's![<][^>]{1,200}?[>]!!g;' |
grep -Pinaso ".{0,60}$PAT.{0,60}" |
grep -Pi --color "$PAT"
done
Put it somewhere in your home and link it to /usr/local/bin, this is how I did it:
Code:
sudo ln -s ~/Apps/CLI/grep-epub.sh /usr/local/bin/grep-epub
Then just use it like this:
To find all occurences of sea in Dubliners:
Code:
grep-epub "sea" Dubliners.epub
To find only the word sea"
Code:
grep-epub " sea " Dubliners.epub
To count, just use it with wc, GNU word count utility.
In Windows, you can use this with Linux subsystem.