Changeset 205 for trunk/twindoi.sh


Ignore:
Timestamp:
05/21/12 11:37:29 (12 years ago)
Author:
pinsard
Message:

remove dupe, fixes,

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/twindoi.sh

    r116 r205  
    88# ========== 
    99# 
    10 # -------------------------- 
    11 # detection of duplicate DOI 
    12 # -------------------------- 
    13 # 
    1410# SYNOPSIS 
    1511# ======== 
     
    1713# :: 
    1814# 
    19 $ twindoi.sh -i filein -t type 
     15twindoi.sh -i filein -t type 
    2016# 
    2117# 
     
    3228# ======== 
    3329# 
    34 # :: 
    35 # 
    36 #  $ ./twindoi.sh -i data/biball.txt -t raw 
    37 # 
    38 # 
    39 # :: 
    40 # 
    41 #  $ ./twindoi.sh -i data/biball.xml -t xml 
     30# To detect duplicate DOI in a raw file:: 
     31# 
     32#  twindoi.sh -i data/biball.txt -t raw 
     33# 
     34# 
     35# To detect duplicate DOI in a XML/DocBook file:: 
     36# 
     37#  twindoi.sh -i data/biball.xml -t xml 
     38# 
     39# To detect duplicate DOI in a bibtex file:: 
     40# 
     41#  twindoi.sh -i data/biball.xml -t bibtex 
    4242# 
    4343# TODO 
     
    5050# :: 
    5151# 
    52 $ ./twindoi.sh -i data/biball.xml -t raw 
     52twindoi.sh -i data/biball.xml -t raw 
    5353# 
    5454# EVOLUTIONS 
     
    5757# $Id$ 
    5858# 
     59# - fplod 20120521T080342Z cratos (Linux) 
     60# 
     61#   * rename type variable to ftype to avoid usage of a reserved word 
     62#   * revision of indentation 
     63#   * typo 
     64#   * add bibtex as file type 
     65# 
    5966# - fplod 20100318T083708Z aedon.locean-ipsl.upmc.fr (Darwin) 
    6067# 
     
    7784system=$(uname) 
    7885case "${system}" in 
    79    AIX|IRIX64) 
    80       echo " www : no specific posix checking" 
    81    ;; 
    82    *) 
    83       set -o posix 
    84    ;; 
     86    AIX|IRIX64) 
     87        echo "${command} : www : no specific posix checking" 
     88    ;; 
     89    *) 
     90       set -o posix 
     91    ;; 
    8592esac 
    8693unset system 
     
    8895set -u 
    8996# 
     97action=$(basename ${0} .sh) 
    9098command=$(basename ${0}) 
    9199log_date=$(date -u +"%Y%m%dT%H%M%SZ") 
    92 log=/tmp/$(basename ${command} .sh).log.${log_date} 
     100log=${PROJECT_LOG}/$(basename ${command} .sh).log.${log_date} 
    93101# 
    94102usage=" Usage : ${command} -i filein -t type" 
     103# 
     104minargcount=4 
     105#echo " narg ${#}" 
     106if [ ${#} -lt ${minargcount} ] 
     107then 
     108    echo "${command} : eee : not enought arguments" 
     109    echo "${usage}" 
     110    exit 1 
     111fi 
     112unset minargcount 
    95113# 
    96114while [ ${#} -gt 0 ] 
    97115do 
    98    case ${1} in 
    99       -i) 
    100          filein=${2} 
    101          shift 
    102       ;; 
    103       -t) 
    104          type=${2} 
    105          shift 
    106       ;; 
    107       *) 
    108         # other choice 
    109         echo "eee : unknown option ${1}" 
    110         echo "${usage}" 
    111         exit 1 
    112       ;; 
    113    esac 
    114    # next flag 
    115    shift 
     116    case ${1} in 
     117        -i) 
     118            filein=${2} 
     119            shift 
     120        ;; 
     121        -t) 
     122            ftype=${2} 
     123            shift 
     124        ;; 
     125        *) 
     126           # other choice 
     127           echo "${command} : eee : unknown option ${1}" 
     128           echo "${usage}" 
     129           exit 1 
     130        ;; 
     131    esac 
     132    # next flag 
     133    shift 
    116134done 
    117135unset usage 
     
    120138if [ ! -f ${filein} ] 
    121139then 
    122    echo "eee : ${filein} not found" 
    123    exit 1 
     140    echo "${command} : eee : ${filein} not found" 
     141    exit 1 
    124142fi 
    125143# 
    126 case ${type} in 
    127    raw)  # file like data/biball.txt 
    128       fileraw=${filein} 
    129    ;; 
    130    xml)   # file like data/biball.xml 
    131       filexml=${filein} 
    132    ;; 
    133    *) 
    134       echo "eee : type should be raw or xml" 
    135       exit 1 
    136    ;; 
     144case ${ftype} in 
     145    raw) # file like data/biball.txt 
     146        fileraw=${filein} 
     147    ;; 
     148    xml) # file like data/biball.xml 
     149        filexml=${filein} 
     150    ;; 
     151    bibtex) # file like data/biball.bib 
     152        filebibtex=${filein} 
     153    ;; 
     154    *) 
     155       echo "${command} : eee : type should be raw, xml or bibtex" 
     156       exit 1 
     157    ;; 
    137158esac 
    138 # 
    139 case ${type} in 
    140    raw) 
    141       grep -i "doi:" ${fileraw} | \ 
    142          sed -e "s/^.*doi: *//" | \ 
    143          sed -e "s/^\(.*\)\.$/ \1/" | \ 
    144          grep -v "???" | \ 
    145          sort -d > /tmp/doilist.txt 
    146    ;; 
    147    xml) 
    148       xml sel -N dbk="http://docbook.org/ns/docbook" \ 
    149          -t -m "//dbk:biblioid[@class='doi']" -v . -n ${filexml} | \ 
    150          grep  -v "???" | \ 
    151          sort -d > /tmp/doilist.txt 
    152    ;; 
    153    *) 
    154       echo "eee : error unknown file type" 
    155       exit 1 
    156    ;; 
     159unset filein 
     160# 
     161case ${ftype} in 
     162    raw) 
     163        grep -i "doi:" ${fileraw} | \ 
     164           sed -e "s/^.*doi: *//" | \ 
     165           sed -e "s/^\(.*\)\.$/ \1/" | \ 
     166           grep -v "???" | \ 
     167           sort -d > ${PROJECT_LOG}/${action}${$}.txt 
     168    ;; 
     169     bibtex) 
     170        grep -i "doi *= *" ${filebibtex} | \ 
     171           sed -e "s/^.*doi *= *//" | \ 
     172           sed -e "s/^\(.*\)\.$/ \1/" | \ 
     173           grep -v "???" | \ 
     174           sort -d > ${PROJECT_LOG}/${action}${$}.txt 
     175    ;; 
     176    xml) 
     177        xml sel -N dbk="http://docbook.org/ns/docbook" \ 
     178          -t -m "//dbk:biblioid[@class='doi']" -v . -n ${filexml} | \ 
     179        grep  -v "???" | \ 
     180        sort -d > ${PROJECT_LOG}/${action}${$}.txt 
     181    ;; 
     182    *) 
     183        echo "${command} : eee : error unknown file type ${ftype}" 
     184        exit 1 
     185    ;; 
    157186esac 
    158 # 
    159 nl=$( cat /tmp/doilist.txt | wc -l ) 
     187unset ftype 
     188# 
     189nl=$( cat ${PROJECT_LOG}/${action}${$}.txt | wc -l ) 
    160190if [ ${nl} -eq 0 ] 
    161191then 
    162    echo "www : no DOI found in ${filein}" 
    163    rm /tmp/doilist.txt 2> /dev/null 
    164    exit 1 
     192    echo "${command} : www : no DOI found in ${filein}" 
     193    rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null 
     194    exit 1 
    165195fi 
    166196n=1 
    167197while [ ${n} -lt ${nl} ] 
    168198do 
    169    l1=$( head -${n} /tmp/doilist.txt | tail -1 ) 
    170    l2=$( head -$(( ${n} + 1 )) /tmp/doilist.txt | tail -1 ) 
    171    [ "${l1}" == "${l2}" ] && echo "eee : line ${n} : ${l1}" 
    172    unset l1 
    173    unet l2 
    174    n=$(( ${n} + 1 )) 
     199    l1=$( head -${n} ${PROJECT_LOG}/${action}${$}.txt | tail -1 ) 
     200    l2=$( head -$(( ${n} + 1 )) ${PROJECT_LOG}/${action}${$}.txt | tail -1 ) 
     201    [ "${l1}" == "${l2}" ] && echo "${command} : eee : line ${n} : ${l1}" 
     202    unset l1 
     203    unset l2 
     204    n=$(( ${n} + 1 )) 
    175205done 
    176206unset n 
    177 # 
    178 rm /tmp/doilist.txt 2> /dev/null 
     207unset nl 
     208# 
     209rm ${PROJECT_LOG}/${action}${$}.txt 2> /dev/null 
     210unset command 
     211unset log 
     212unset log_date 
     213# 
     214#++set 
    179215exit 0 
Note: See TracChangeset for help on using the changeset viewer.