Если у Вас есть Python и волшебство Python. Например,
#!/usr/bin/env python
import magic
import os
path=sys.argv[1]
mime = magic.open(magic.MAGIC_NONE)
mime.load()
for r,d,f in os.walk(path):
for files in f:
filename=os.path.join(r,files)
filetype=mime.file(filename)
if "image" in filetype:
print "File: %s is %s" %(filename, filetype)
Я знаю нескольких средств индексирования ту поддержку документы Word. Такие инструменты позволяют Вам индексировать документы, затем эффективно искать слова в индексе. Они не разрешают полнотекстовые поиски.
DOCx сжат, и это не текстовый формат. Таким образом, то, в чем Вы нуждаетесь, является преобразователем сначала. После этого можно использовать find
команда на преобразованном файле (файлах).
grep
?
– Gilles 'SO- stop being evil'
07.01.2012, 01:32
Мое grep
решение как функцию, которую вы можете вставить в свой.bashrc
docx_search(){ local arg wordfile terms=() root=${root:-/}; for arg; do terms+=(-e "$arg"); done; find 2>/dev/null "${root%/}/" -iname '*.docx' -exec bash -c "$(declare -p terms)"'; for arg; do unzip -p "$arg" 2>/dev/null | grep --quiet --ignore-case --fixed-strings "${terms[@]}" && printf %s\\n "$arg"; done' _ {} +; }
Он будет искать любое (нечувствительное к регистру )вхождение своих аргументов и выводить соответствующее местоположение файла docx.
Примеры:
$ docx_search 'my example sentence'
/cygdrive/d/example sentences.docx
/cygdrive/c/Users/my user/Documents/example sentences.docx
$ root='/cygdrive/c/Users/my user/' docx_search 'seldom' 'full sentence'
/cygdrive/c/Users/my user/Documents/example sentences.docx
$
Версия для чтения:
docx_search(){
local arg wordfile terms=() root=${root:-/}
# this 'root' assignment allows you to search in a specific location like /cygdrive/c/ instead of everywhere on the machine
for arg; do terms+=(-e "$arg"); done
# We inject the terms to search inside the string with declare -p`
find 2>/dev/null "${root%/}/" -iname '*.docx' -exec \
bash -c "$(declare -p terms)"';
for arg; do
unzip -p "$arg" 2>/dev/null |
grep --quiet --ignore-case --fixed-strings "${terms[@]}" &&
printf %s\\n "$arg"
done' _ {} +
}