2014-08-29

чорновик скрипта для порівняння двох книжок

нехай поки тут полежить
#!/bin/bash
tmpfs="/tmp/"
book1="${tmpfs}book1_`basename "$1"`"
book2="${tmpfs}book2_`basename "$2"`"

function listwords {
  cat "${1}" |\
  tr '\n' ' ' |\
  sed 's/\t\| / /g' |\
  sed 's/–\|—\|‑/-/g' |\
  sed 's/«\|»\|„\|“/\"/g' |\
  sed 's/…/.../g' |\
  sed 's/\s/\n/g' |\
  sed '/^\s$/d' |\
  sed '/^$/d' \
  > "${2}"
}

unoconv -f txt --stdout "$1" > "${book1}.txt" || exit $?
unoconv -f txt --stdout "$2" > "${book2}.txt" || exit $?
ls "${book1}.txt" "${book2}.txt" || exit $?

listwords "${book1}.txt" "${book1}_.txt"
listwords "${book2}.txt" "${book2}_.txt"

meld "${book1}_.txt" "${book2}_.txt"
#diff -y --suppress-common-lines "${book1}_.txt" "${book2}_.txt" | less
rm "${book1}_.txt" "${book2}_.txt" "${book1}.txt" "${book2}.txt"