forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrebook.sh
More file actions
executable file
·30 lines (26 loc) · 815 Bytes
/
grebook.sh
File metadata and controls
executable file
·30 lines (26 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
# Adapted from mosh https://unix.stackexchange.com/a/389119
# The colorizing doesn't work for me, but I've left it in
# in case it turns out to work in some cases.
# For a simpler solution, zipgrep can search epubs.
PAT=${1:?"Usage: grep-epub PAT *.epub files to grep"}
shift
: ${1:?"Need epub files to grep"}
if [ $# -ge 1 ]; then
extra="--with-filename"
else
extra=
fi
for i in $* ;do
output=$(
unzip -p $i "*.htm*" "*.xml" "*.opf" | # unzip only html and content files to stdin
perl -lpe 's![<][^>]{1,200}?[>]!!g;' | # get rid of small html <b>tags
grep -Piaso ".{0,30}$PAT.{0,30}" | # keep some context around matches
grep -Pi --color "$PAT" # color the matches.
)
if [ x"$output" != x ]; then
echo "======" $i
echo $output
echo
fi
done