#! /bin/sh #+ # # .. program:: twinloceanbibid.sh # # ================== # twinloceanbibid.sh # ================== # # SYNOPSIS # ======== # # .. code-block:: bash # # twinloceanbibid.sh -i filein -t type # # DESCRIPTION # =========== # # .. option:: -i # .. option:: -t # # detection of duplicate loceanbibid # # EXAMPLES # ======== # # To detect duplicate loceanbibid in a bibtex file: # # .. code-block:: bash # # twinloceanbibid.sh -i ../data/biblioref.bib -t bibtex # # TODO # ==== # # ++ option debug # # show the greatest loceanbibid # # EVOLUTIONS # ========== # # $Id$ # # $URL$ # # - fplod 20120927T101302Z cratos.locean-ipsl.upmc.fr (Linux) # # * show the greatest loceanbibid # # - fplod 20120703T155110Z cratos (Linux) # # * creation from twindoi.sh # #- # system=$(uname) case "${system}" in AIX|IRIX64) echo "${command} : www : no specific posix checking" ;; *) set -o posix ;; esac unset system # set -u # action=$(basename ${0} .sh) command=$(basename ${0}) log_date=$(date -u +"%Y%m%dT%H%M%SZ") log=${PROJECT_LOG}/$(basename ${command} .sh).log.${log_date} # usage=" Usage : ${command} -i filein -t type" # minargcount=4 #echo " narg ${#}" if [ ${#} -lt ${minargcount} ] then echo "${command} : eee : not enough arguments" echo "${usage}" exit 1 fi unset minargcount # while [ ${#} -gt 0 ] do case ${1} in -i) filein=${2} shift ;; -t) ftype=${2} shift ;; *) # other choice echo "${command} : eee : unknown option ${1}" echo "${usage}" exit 1 ;; esac # next flag shift done unset usage # # check for filein if [ ! -f ${filein} ] then echo "${command} : eee : ${filein} not found" exit 1 fi # case ${ftype} in bibtex) # file like data/biball.bib filebibtex=${filein} ;; *) echo "${command} : eee : type should be bibtex" exit 1 ;; esac unset filein # case ${ftype} in bibtex) grep -i "loceanbibid *= *" ${filebibtex} | \ sed -e "s/^.*loceanbibid *= *//" | \ sed -e "s/^\(.*\)\.$/ \1/" | \ grep -v "???" | \ sort -d > ${PROJECT_LOG}/${action}${$}.txt ;; *) echo "${command} : eee : error unknown file type ${ftype}" exit 1 ;; esac unset ftype # nl=$( cat ${PROJECT_LOG}/${action}${$}.txt | wc -l ) if [ ${nl} -eq 0 ] then echo "${command} : www : no loceanbibid found in ${filein}" rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null exit 1 fi n=1 while [ ${n} -lt ${nl} ] do l1=$( head -${n} ${PROJECT_LOG}/${action}${$}.txt | tail -1 ) l2=$( head -$(( ${n} + 1 )) ${PROJECT_LOG}/${action}${$}.txt | tail -1 ) [ "${l1}" == "${l2}" ] && echo "${command} : eee : line ${n} : ${l1}" unset l1 unset l2 n=$(( ${n} + 1 )) done unset n unset nl # greatestid=$(grep loceanbibid ${filebibtex} | \ grep -v comment |sed -e 's/[^0-9]//g' | \ sort -n | tail -n 1) echo "greatest id = ${greatestid}" # # cleaning rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null unset command unset log unset log_date # #++set exit 0