From: Stefan Metzmacher Date: Wed, 5 Aug 2015 11:06:22 +0000 (+0200) Subject: add import_oldnews.sh helper script X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=c9f87ffacfb0daf011d8808a557c21f2c89a3e91;p=metze%2Ftest%2Fsamba-web.git add import_oldnews.sh helper script This can be used like this: ./import_oldnews.sh generated_news/latest_10_headlines.html generated_news/latest_10_bodies.html Signed-off-by: Stefan Metzmacher --- diff --git a/import_oldnews.sh b/import_oldnews.sh new file mode 100755 index 00000000..f6ab6bc6 --- /dev/null +++ b/import_oldnews.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# + +LC_ALL=C +export LC_ALL +LANG=C +export LANG +LANGUAGE=C +export LANGUAGE + +set -u +set -e +umask 0022 + +HEADLINES=${1} +BODIES=${2} + +LINES="$(cat ${HEADLINES} | grep '
  • ')" +NLINES=$(echo "${LINES}" | wc -l) + +BODYH5="$(grep --line-number '
    ' ${BODIES})" + +for i in $(seq 1 $NLINES); do + l=$(echo "${LINES}" | head -${i} | tail -1 | sed -e 's!^[\t ]*!!') + d=$(echo "${l}" | sed -e 's!^
  • \([^<]*\)" + echo "${l}" + echo "" + } > ${headlinefile} + + boundary=$(echo "${BODYH5}" | grep -A1 "
    " | cut -d ':' -f1) + tmp=$(echo "${boundary}" | wc -l) + case "${tmp}" in + 2) + begin=$(echo "${boundary}" | head -1) + next=$(echo "${boundary}" | tail -1) + end=$(expr ${next} - 1) + len=$(expr ${end} - ${begin}) + ;; + 1) + len="10000" + ;; + *) + echo "invalid boundary:" + echo "${boundary}" + exit 1 + ;; + esac + echo "${i}: ${bodyfile}" + { + echo "" + grep -A${len} "
    " ${BODIES} + echo "" + } > ${bodyfile} +done