View Single Post
Old 03-10-2018, 03:43 AM   #13
GERGE
Guru
GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.GERGE ought to be getting tired of karma fortunes by now.
 
Posts: 733
Karma: 5797160
Join Date: Jun 2010
Location: Istanbul
Device: Kobo Libra
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.

Last edited by GERGE; 03-10-2018 at 03:48 AM.
GERGE is offline   Reply With Quote