Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function soffice_conv(){
- mkdir -p ./tmp_s243a_convert_$$
- soffice --headless --convert-to txt:Text --outdir ./tmp_$$ "$1" #2>/dev/null >/dev/null
- ls -1 ./tmp_$$ | xargs -I % cat '%'
- rm -rf ./tmp_s243a_convert_$$
- }
- function wvText_conv(){
- mkdir -p ./tmp_s243a_convert_$$
- wvText ./tmp_$$ "$1" ./tmp_$$/"$1".txt #2>/dev/null >/dev/null
- ls -1 ./tmp_$$ | xargs -I % cat '%'
- rm -rf ./tmp_s243a_convert_$$
- }
- if [ ! -z "`which unoconv`" ]; then
- CONV_PGM=unoconv
- CONV_CMD="unoconv --stdout -f text"
- elif [ ! -z "`which soffice`" ]; then
- CONV_PGM=soffice
- CONV_CMD="soffice_conv" #http://hitekhedhelp.blogspot.com/2011/08/omega-overview.html
- elif [ ! -z "`which abiword`" ]; then
- CONV_PGM=abiword
- CONV_CMD="abiword --to=txt --to-name=fd://1"
- fi
- if [ ! -z "`which file`" ]; then #maybe also check that the file command actually works
- if [[ "$(file --mime-type "$1")" = */rtf ]]; then #text/rtf
- if [ ! -z "`which unrtf`" ]; then
- CONV_PGM="unrtf"
- CONV_CMD="unrtf --text"
- fi
- #Possible utilities;
- #TEXTUTIL/ https://superuser.com/questions/243084/rtf-to-txt-on-unix
- elif [[ "$(file --mime-type "$1")" = */msword ]]; then #application/msword
- if [ ! -z "`which antiword`" ]; then
- CONV_PGM="antiword"
- CONV_CMD="antiword"
- elif [ ! -z "`which wvText`" ] && [ -z "$CONV_CMD" ]; then #Some office tools may be better than this util.
- CONV_PGM="wvText"
- CONV_CMD="wvText_conv"
- fi
- elif [[ "$(file --mime-type "$1")" = */vnd.oasis.opendocument.* ]]; then #nd.oasis.opendocument
- if [ ! -z "`which odt2txt`" ]; then
- CONV_PGM="odt2txt"
- CONV_CMD="odt2txt"
- elif [ ! z- "`which odf2txt`" ] && [ -z "$CONV_PGM" ] && [ ! z- "`which python`" ]; then
- CONV_PGM="odf2txt"
- CONV_CMD="odf2txt"
- fi
- fi
- fi
- $CONV_CMD "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement