source: trunk/twindoi.sh @ 94

Last change on this file since 94 was 94, checked in by pinsard, 14 years ago

add man troff output of manuals

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
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#
63system=$(uname)
64case "${system}" in
65 AIX|IRIX64)
66  echo " www : no specific posix checking"
67 ;;
68 *)
69  set -o posix
70 ;;
71esac
72command=$(basename ${0})
73log_date=$(date -u +"%Y%m%dT%H%M%SZ")
74log=/tmp/$(basename ${command} .sh).log.${log_date}
75#
76usage=" Usage : ${command} -i filein -t type"
77#
78while [ ! -z "${1}" ] # ++ pb bash
79do
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
95done
96set -u
97#
98# check for filein
99if [ ! -f ${filein} ]
100then
101  echo "eee : ${filein} not found"
102  exit 1
103fi
104#
105case ${type} in
106raw) # file like data/biball.txt
107 fileraw=${filein}
108;;
109xml)  # file like data/biball.xml
110 filexml=${filein}
111;;
112*)
113   echo "eee : type should be raw or xml"
114   exit 1
115;;
116esac
117#
118case ${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        ;;
136esac
137#
138nl=$( cat /tmp/doilist.txt | wc -l )
139if [ ${nl} -eq 0 ]
140then
141   echo "www : no DOI found in ${filein}"
142   rm /tmp/doilist.txt 2> /dev/null
143   exit 1
144fi
145n=1
146while [ ${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}"
151n=$(( ${n} + 1 ))
152done
153#
154rm /tmp/doilist.txt 2> /dev/null
155exit 0
Note: See TracBrowser for help on using the repository browser.