[BACK]Return to expand.sh CVS log [TXT][DIR] Up to [local] / web

File: [local] / web / expand.sh (download)

Revision 1.2, Mon Jul 20 01:44:48 2015 JST (8 years, 10 months ago) by hako
Branch: MAIN
Changes since 1.1: +6 -6 lines

cat

#!/bin/sh
# Expand article-xml files from a single xml file (publication data) made by BibDesk of OSX
# by Hiroshi Hakoyama
# POSIX sh
# example:
# cd www/publications
# expand.sh ~/web/papers.xml
# make

filename=$1
tmpfile=$(mktemp)
cp ${filename} ${tmpfile}

# some dirty modifications
(rm ${tmpfile};  sed s/"箱山, 洋."/"箱山 洋"/g > ${tmpfile}) < ${tmpfile}
(rm ${tmpfile};  sed s/"巌佐, 庸."/"巌佐 庸"/g > ${tmpfile}) < ${tmpfile}
(rm ${tmpfile};  sed /\>NA\</d > ${tmpfile}) < ${tmpfile}
(rm ${tmpfile};  sed /\>NA\./d > ${tmpfile}) < ${tmpfile}
(rm ${tmpfile};  sed -E 's/\?\./\?/g' > ${tmpfile}) < ${tmpfile}
(rm ${tmpfile};  sed -E 's/?\./?/g' > ${tmpfile}) < ${tmpfile}

# list of the start line-number and end line-number of articles
start=`sed -n '/<article/=' ${tmpfile}`
end=`sed -n '/article>/=' ${tmpfile}`

# make article files
set $start
i=1
length=$#
while test $i -le $length ; do
  set dummy $start
  shift $i
  s=$1
  set dummy $end
  shift $i
  e=$1
  id=`sed -n ${s}p ${tmpfile} | sed -e 's/[^"]*"\([^"]*\)".*/\1/'`
  sed -n ${s},${e}p ${tmpfile} > $id.xml
  i=`expr $i + 1`
done

rm ${tmpfile}

exit 0