docxファイルを検索するためのコマンドラインツール

docxファイルを検索するためのコマンドラインツール

docxファイルからテキスト検索を実行するコマンドラインツールはありますか?試してみましたが、greptxtファイルとxmlファイルではうまく機能しますが、docxでは機能しません。まず、docxをtxtに変換できますが、docxファイルで直接機能するツールを好みます。 Cygwinで動作するにはこのツールが必要です。

OP編集:後でgrepを実装する最も簡単な方法は、実際にこれらのdocxをtxtに変換してからgrepすることです。

答え1

私の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' _ {} +
}

答え2

私はWord文書をサポートするいくつかのインデックスツールを知っています。これらのツールを使用すると、文書を索引付けしてから索引から単語を効率的に検索できます。全文検索を許可しません。

答え3

DOCxは圧縮されており、テキスト形式ではありません。だからあなたに必要なことコンバーター最初。その後、find変換されたファイルに対してコマンドを使用できます。

答え4

見たことがありますか?オープンオフィス忍者
(cygwinのサポートについて知らない)

関連情報