]>
nuage.metani.fr Git - 3GPP.git/blob - bin/docx2txt.sh
3 if [[ $# -eq 0 ]] ; then
4 echo "Usage: ${0##*/} file [files]"
5 echo "Extract ASN.1 from one or more 3GPP 38.331 docx files and save them to .txt files"
10 echo "Cannot write to current directory"
17 Linux
) libreoffice
="libreoffice" ;;
18 CYGWIN
*) libreoffice
="soffice" ;;
19 *) echo "Unkown platform $platform"
23 if [[ ! -x $(which "$libreoffice") ]] ; then
24 echo "Cannot find libreoffice executable"
25 echo "Make sure it is installed and the PATH variable includes its path"
29 while [ "$#" -gt 0 ]; do
33 if [[ ! -f "$1" ]] || [[ ! -r "$1" ]] ; then
34 echo "$1 is not a readable file"
39 $libreoffice --convert-to txt
"$1"
41 if [[ ! -f "${1%.docx}.txt" ]] || [[ ! -r "${1%.docx}.txt" ]] ; then
42 echo "libreoffice did not create ${1%.docx}.txt"
48 # Replace EN-DASH (UTF-8 encoding) at line start with -
49 Linux
) LC_ALL
=C
sed -i $
's/^\u2013/-/g' "${1%.docx}.txt" ;;
51 # Replace EN-DASH (Windows-1252 encoding) at line start with -
52 # Remove CR (0x0d) put by libreoffice in windows before each LF (0x0a)
53 CYGWIN
*) LC_ALL
=C
sed -i $
's/^\x96/-/g; s/\r$//' "${1%.docx}.txt" ;;
54 *) echo "Unkown platform $platform"
58 # Changes things that should not be so in the specification
59 # Change "-- Cond N3C MP" to "-- Cond N3C-MP" (to respect condition naming rules)
60 LC_ALL
=C
sed -i 's/-- Cond N3C MP/-- Cond N3C-MP/' "${1%.docx}.txt"
61 LC_ALL
=C
sed -i 's/^N3C MP/N3C-MP/' "${1%.docx}.txt"
62 LC_ALL
=C
sed -i 's/-- Cond HOAndServCellAdd,$/-- Cond HOAndServCellAdd/' "${1%.docx}.txt"