source: trunk/twindoi.sh @ 76

Last change on this file since 76 was 75, checked in by pinsard, 16 years ago

comments in shell scripts in ReStructured? Text

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1#! /bin/sh
2#+
3# NAME
4# ====
5#
6# twindoi.sh - detection of duplicate DOI
7#
8# SYNOPSYS
9# ========
10#
11# ::
12#
13#  $ twindoi.sh -i filein -t type
14#
15#
16# DESCRIPTION
17# ===========
18#
19#
20# detection of duplicate DOI
21#
22# EXAMPLES
23# ========
24#
25# ::
26#
27#  $ ./twindoi.sh -i data/biball.txt -t raw
28#
29#
30# ::
31#
32#  $ ./twindoi.sh -i data/biball.xml -t xml
33#
34# FILES
35# =====
36#
37# original location
38# ~~~~~~~~~~~~~~~~~
39#
40# /usr/home/fplod/src/superbib_ws/twindoi.sh sur aedon.locean-ipsl.upmc.fr
41#
42#
43# EVOLUTIONS
44# ==========
45#
46# ++ option debug
47#
48# ++ the following command wich is not convinient
49# (xml vs txt) did not give any alert and check inside xml comments
50# ::
51#
52#  $ ./twindoi.sh -i data/biball.xml -t raw
53#
54#
55# $Id$
56#
57# - fplod 2008-05-05T14:26:31Z aedon.locean-ipsl.upmc.fr (Darwin)
58#
59#  * usage of xml(starlet) for doi extraction in xml file
60#
61# - fplod 2007-06-20T16:12:22Z aedon.locean-ipsl.upmc.fr (Darwin)
62#
63#  * consolidation and homogeneisation
64#
65# - smasson 2007-06-20T16:11:47Z
66#
67#  * creation
68#-
69#
70system=$(uname)
71case "${system}" in
72 AIX|IRIX64)
73  echo " www : no specific posix checking"
74 ;;
75 *)
76  set -o posix
77 ;;
78esac
79command=$(basename ${0})
80log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
81log=/tmp/${command}.${log_date}
82#
83usage=" Usage : ${command} -i filein -t type"
84#
85while [ ! -z "${1}" ] # ++ pb bash
86do
87 case ${1} in
88 -i) # filein
89  filein=${2}
90  shift
91 ;;
92 -t) # type
93  type=${2}
94  shift
95 ;;
96 *) # other choice
97  echo "${usage}"
98  exit 1
99 ;;
100 esac
101 shift # next flag
102done
103set -u
104#
105# check for filein
106if [ ! -f ${filein} ]
107then
108  echo "eee : ${filein} not found"
109  exit 1
110fi
111#
112case ${type} in
113raw) # file like data/biball.txt
114 fileraw=${filein}
115;;
116xml)  # file like data/biball.xml
117 filexml=${filein}
118;;
119*)
120   echo "eee : type should be raw or xml"
121   exit 1
122;;
123esac
124#
125case ${type} in
126     raw)
127        grep -i "doi:" ${fileraw} | \
128        sed -e "s/^.*doi: *//" | \
129        sed -e "s/^\(.*\)\.$/ \1/" | \
130        grep -v "???" | \
131        sort -d > /tmp/doilist.txt
132        ;;
133     xml)
134        xml sel -N dbk="http://docbook.org/ns/docbook" \
135        -t -m "//dbk:biblioid[@class='doi']" -v . -n ${filexml} | \
136        grep -v "???" | \
137        sort -d > /tmp/doilist.txt
138        ;;
139     *)
140        echo "eee : error unknown file type"
141        exit 1
142        ;;
143esac
144#
145nl=$( cat /tmp/doilist.txt | wc -l )
146if [ ${nl} -eq 0 ]
147then
148   echo "www : no DOI found in ${filein}"
149   rm /tmp/doilist.txt 2> /dev/null
150   exit 1
151fi
152n=1
153while [ ${n} -lt ${nl} ]
154   do
155   l1=$( head -${n} /tmp/doilist.txt | tail -1 )
156   l2=$( head -$(( ${n} + 1 )) /tmp/doilist.txt | tail -1 )
157   [ "${l1}" == "${l2}" ] && echo "eee : line ${n} : ${l1}"
158n=$(( ${n} + 1 ))
159done
160#
161rm /tmp/doilist.txt 2> /dev/null
162exit 0
Note: See TracBrowser for help on using the repository browser.