
docx 파일에서 텍스트 검색을 수행하는 명령줄 도구가 있습니까? 시도해 보았지만 grep
txt 및 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 문서를 지원하는 여러 색인 도구를 알고 있습니다. 이러한 도구를 사용하면 문서를 색인화한 다음 색인에서 단어를 효율적으로 검색할 수 있습니다. 전체 텍스트 검색을 허용하지 않습니다.
- 기록(그리고반의어그리고무선 소프트웨어). Cygwin 지원을 모르겠습니다.
- 루체른, 그리고약간의 조립이 필요함. 나는 그것이 Cygwin에서 작동할 것이라고 믿습니다.
- 스핑크스, 그리고모든 docx-텍스트 변환기.Windows는 기본적으로 지원합니다..
- 추적 장치(아직 문제가 있을 수 있습니다.). Cygwin 지원이 불규칙해 보입니다.
답변3
DOCx는 압축되어 있으며 텍스트 형식이 아닙니다. 그래서 당신에게 필요한 것은변환기첫 번째. 이후 find
변환된 파일에 대해 명령을 사용할 수 있습니다.
답변4
본 적 있나요?오픈 오피스 닌자?
(cygwin 지원에 대해 모른다)