find . -name "*.ooutline" -print0 | xargs -0 -n1 unzip -c | grep -m 10 -Eo ".{0,20}$1.{0,20}"
".ooutline' files are zipped OmniOutliner files. I want to find them, including recursively in subdirectories; pipe the names to unzip; have unzip unzip each .ooutline file into memory; then grep the contents of the unzipped file in memory.
I haven't had much luck trying to do this with find. I do have a working bash shell script, as follows:
#!/bin/bash
for file in *.ooutline; do
if ( unzip -c "$file" | grep --label="$file" -H -m 10 -Eo ".{0,20}$1.{0,20}" ) ; then
printf "\n\n"
fi
done
I'd like to be able to do this on one line with find. I'd appreciate any advice on this. Thank you.
THE NEXT DAY
Progress! This works but only on the one of the files in the list. This means the idea is right, but I have some detail wrong. Note: I got the find-exec-unzip idea from another post on stack: I do have filenames with spaces.
find . -name '*.zip' -exec sh -c 'unzip -c -d "`dirname \"{}\"`" "{}"' ';' | grep -m 10 -Eo ".{0,20}Peter.{0,20}"
I tried this
find . -name '*.zip' -exec sh -c 'unzip -c "{}"' ';' | grep -m 10 -Eo ".{0,20}Peter.{0,20}"
and it returned these results
Version Peter sleep and wa reason they brought Peter here for this missi Dr Adkins finds Peter on his knees prayin g outside ICU. Peter is convinced Five i s not go there yet. Peter gives him a speech
...so it's definitely returning something from one file (an analysis of a science fiction novel).