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