2

I tried the answers here, but without luck.

find . -name "*.epub" -exec zipgrep pattern {} \;

showed me "matched", but didn't give me the matching epub file back. Also, it returned huge blobs of data, which were hard to grep through.

grep -a didn't work at all.

I want something like grep -R but for epub files.

1
  • I think zipgrep should pass other command line options to egrep, so did you try adding -H (or -l if you want only the matching filename)? Commented Jun 28, 2018 at 15:57

2 Answers 2

1

This will give you the full path to all the *.epub files.

find / -name *.epub -exec ls {} \; 2>/dev/null

If you want to store that ouput in a list:

find / -name *.epub -exec ls {} \; 2>/dev/null >> /tmp/list

If you want to search that list for a string I would use a for loop. If you are getting huge blobs of data it may see them as one long line. this will print the patter and the 5 char before and after.

for i in `cat /tmp/list` ; do echo $i ; grep -a -o -p '.{0,5}pattern.{0,5}' ; done
4
  • Thanks a lot! Thats a super useful combination of commands. However, the first one just doesn't give me anything back? (I have a lot of epub files in that folder/subfolder).
    – JJ Abrams
    Commented Jun 28, 2018 at 16:45
  • Which distro are you using? This works with RHEL6. $ find /tmp -name *.epub -exec ls {} \; 2>/dev/null /tmp/test/subdir/sub.epub /tmp/test/subdir/subdir2/sub2.epub /tmp/test/test2.epub /tmp/test.epub
    – SpruceTips
    Commented Jun 28, 2018 at 17:09
  • 1
    You do not need -exec ls, this is the default behaviour of find. Commented Jun 28, 2018 at 17:09
  • @SpruceTips: I am using Ubuntu 16.04 and I ran the same command (just replaced the / with a . )
    – JJ Abrams
    Commented Jun 28, 2018 at 17:30
1

I would use:

find . -name '*.epub'  -exec zipgrep -q {pattern} {} \; -print
  • -q suppresses the display of hits
  • since zipgrep returns 0 only if it finds a match, the -exec zipgrep ... acts as a filter, so the -print is only executed if there was a match (in case you need it, it can be another -exec that will only be executed on the matching files).
1
  • I get quite some errors when running the command: caution: filename not matched: OEBPS/images/[Originaldateien]/ caution: filename not matched: OEBPS/images/[Originaldateien]/929-4-8300-2179-8_img_cover.jpg caution: filename not matched: OEBPS/images/[Originaldateien]/logo.bmp zipinfo: cannot find or open ./new_ebooks/Harry, Fontaine - Final Chapter Three.epub, ./new_ebooks/Harry, Fontaine - Final Chapter Three.epub.zip or ./new_ebooks/Harry, Fontaine - Final Chapter Three.epub.ZIP. /usr/bin/zipgrep: 97: test: -eq: unexpected operator /usr/bin/zipgrep: 100: test: Illegal number:
    – JJ Abrams
    Commented Jun 28, 2018 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .