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 | # |
---|
58 | system=$(uname) |
---|
59 | case "${system}" in |
---|
60 | AIX|IRIX64) |
---|
61 | echo "${command} : www : no specific posix checking" |
---|
62 | ;; |
---|
63 | *) |
---|
64 | set -o posix |
---|
65 | ;; |
---|
66 | esac |
---|
67 | unset system |
---|
68 | # |
---|
69 | set -u |
---|
70 | # |
---|
71 | action=$(basename ${0} .sh) |
---|
72 | command=$(basename ${0}) |
---|
73 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
74 | log=${PROJECT_LOG}/$(basename ${command} .sh).log.${log_date} |
---|
75 | # |
---|
76 | usage=" Usage : ${command} -i filein -t type" |
---|
77 | # |
---|
78 | minargcount=4 |
---|
79 | #echo " narg ${#}" |
---|
80 | if [ ${#} -lt ${minargcount} ] |
---|
81 | then |
---|
82 | echo "${command} : eee : not enough arguments" |
---|
83 | echo "${usage}" |
---|
84 | exit 1 |
---|
85 | fi |
---|
86 | unset minargcount |
---|
87 | # |
---|
88 | while [ ${#} -gt 0 ] |
---|
89 | do |
---|
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 |
---|
108 | done |
---|
109 | unset usage |
---|
110 | # |
---|
111 | # check for filein |
---|
112 | if [ ! -f ${filein} ] |
---|
113 | then |
---|
114 | echo "${command} : eee : ${filein} not found" |
---|
115 | exit 1 |
---|
116 | fi |
---|
117 | # |
---|
118 | case ${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 | ;; |
---|
126 | esac |
---|
127 | unset filein |
---|
128 | # |
---|
129 | case ${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 | ;; |
---|
141 | esac |
---|
142 | unset ftype |
---|
143 | # |
---|
144 | nl=$( cat ${PROJECT_LOG}/${action}${$}.txt | wc -l ) |
---|
145 | if [ ${nl} -eq 0 ] |
---|
146 | then |
---|
147 | echo "${command} : www : no loceanbibid found in ${filein}" |
---|
148 | rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null |
---|
149 | exit 1 |
---|
150 | fi |
---|
151 | n=1 |
---|
152 | while [ ${n} -lt ${nl} ] |
---|
153 | do |
---|
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 )) |
---|
160 | done |
---|
161 | unset n |
---|
162 | unset nl |
---|
163 | # |
---|
164 | greatestid=$(grep loceanbibid ${filebibtex} | \ |
---|
165 | grep -v comment |sed -e 's/[^0-9]//g' | \ |
---|
166 | sort -n | tail -n 1) |
---|
167 | echo "greatest id = ${greatestid}" |
---|
168 | # |
---|
169 | # cleaning |
---|
170 | rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null |
---|
171 | unset command |
---|
172 | unset log |
---|
173 | unset log_date |
---|
174 | # |
---|
175 | #++set |
---|
176 | exit 0 |
---|