source: branches/bibliolocean/src/twinloceanbibid.sh @ 354

Last change on this file since 354 was 354, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1#! /bin/sh
2#+
3#
4# .. program:: twinloceanbibid.sh
5#
6# ==================
7# twinloceanbibid.sh
8# ==================
9#
10# SYNOPSIS
11# ========
12#
13# .. code-block:: bash
14#
15#    twinloceanbibid.sh -i filein -t type
16#
17# DESCRIPTION
18# ===========
19#
20# .. option:: -i <filein>
21# .. option:: -t <type>
22#
23# detection of duplicate loceanbibid
24#
25# EXAMPLES
26# ========
27#
28# To detect duplicate loceanbibid in a bibtex file:
29#
30# .. code-block:: bash
31#
32#    twinloceanbibid.sh -i ../data/biblioref.bib -t bibtex
33#
34# TODO
35# ====
36#
37# ++ option debug
38#
39# show the greatest loceanbibid
40#
41# EVOLUTIONS
42# ==========
43#
44# $Id$
45#
46# $URL$
47#
48# - fplod 20120927T101302Z cratos.locean-ipsl.upmc.fr (Linux)
49#
50#   * show the greatest loceanbibid
51#
52# - fplod 20120703T155110Z cratos (Linux)
53#
54#   * creation from twindoi.sh
55#
56#-
57#
58system=$(uname)
59case "${system}" in
60    AIX|IRIX64)
61        echo "${command} : www : no specific posix checking"
62    ;;
63    *)
64        set -o posix
65    ;;
66esac
67unset system
68#
69set -u
70#
71action=$(basename ${0} .sh)
72command=$(basename ${0})
73log_date=$(date -u +"%Y%m%dT%H%M%SZ")
74log=${PROJECT_LOG}/$(basename ${command} .sh).log.${log_date}
75#
76usage=" Usage : ${command} -i filein -t type"
77#
78minargcount=4
79#echo " narg ${#}"
80if [ ${#} -lt ${minargcount} ]
81then
82    echo "${command} : eee : not enough arguments"
83    echo "${usage}"
84    exit 1
85fi
86unset minargcount
87#
88while [ ${#} -gt 0 ]
89do
90    case ${1} in
91        -i)
92            filein=${2}
93            shift
94        ;;
95        -t)
96            ftype=${2}
97            shift
98        ;;
99        *)
100            # other choice
101            echo "${command} : eee : unknown option ${1}"
102            echo "${usage}"
103            exit 1
104        ;;
105    esac
106    # next flag
107    shift
108done
109unset usage
110#
111# check for filein
112if [ ! -f ${filein} ]
113then
114    echo "${command} : eee : ${filein} not found"
115    exit 1
116fi
117#
118case ${ftype} in
119    bibtex) # file like data/biball.bib
120        filebibtex=${filein}
121    ;;
122    *)
123        echo "${command} : eee : type should be bibtex"
124        exit 1
125    ;;
126esac
127unset filein
128#
129case ${ftype} in
130    bibtex)
131        grep -i "loceanbibid *= *" ${filebibtex} | \
132        sed -e "s/^.*loceanbibid *= *//" | \
133        sed -e "s/^\(.*\)\.$/ \1/" | \
134        grep -v "???" | \
135        sort -d > ${PROJECT_LOG}/${action}${$}.txt
136    ;;
137    *)
138        echo "${command} : eee : error unknown file type ${ftype}"
139        exit 1
140    ;;
141esac
142unset ftype
143#
144nl=$( cat ${PROJECT_LOG}/${action}${$}.txt | wc -l )
145if [ ${nl} -eq 0 ]
146then
147    echo "${command} : www : no loceanbibid found in ${filein}"
148    rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null
149    exit 1
150fi
151n=1
152while [ ${n} -lt ${nl} ]
153do
154    l1=$( head -${n} ${PROJECT_LOG}/${action}${$}.txt | tail -1 )
155    l2=$( head -$(( ${n} + 1 )) ${PROJECT_LOG}/${action}${$}.txt | tail -1 )
156    [ "${l1}" == "${l2}" ] && echo "${command} : eee : line ${n} : ${l1}"
157    unset l1
158    unset l2
159    n=$(( ${n} + 1 ))
160done
161unset n
162unset nl
163#
164greatestid=$(grep loceanbibid ${filebibtex} | \
165grep -v comment |sed -e 's/[^0-9]//g' | \
166sort -n | tail -n 1)
167echo "greatest id = ${greatestid}"
168#
169# cleaning
170rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null
171unset command
172unset log
173unset log_date
174#
175#++set
176exit 0
Note: See TracBrowser for help on using the repository browser.