Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#! /bin/bash

##
## $1 = list of ALCARECO files to process
## $2: label to append to files in output (optional)


if [ "$#" == 0 ]; then
   echo "Usage: cntevts_in_file.sh <filelist>"
   exit 1
fi

TAG="nevents${2}"

rm -f $TAG.*

for file in $( cat $1 )
  do
  echo
  echo "Querying DBS for $file"
  echo "---> $(./query.py --input="find file.numevents where file=$file"  --verbose=0 --limit=-1)" >> $TAG".tmp"
####--limit=-1 
  echo "#events: $( tail -n 2 $TAG.tmp )"
done



IND=0
takenext=0

for line in $(cat $TAG".tmp")
do
let IND=IND+1

if [ $IND == 1 ] 
then
echo
fi

if [ $takenext -ge 1 ] 
then
let takenext=takenext+1
fi


#if [ "$line" == "file.numeventss" ] 
if [ "$line" == "Found" ] 
then
#echo "~~~~LINE is $line"
#echo "~~~~IND is $IND"
takenext=1
fi

#the number of events appears as 3rd field after the 
#word 'Found'

if [ $takenext == 4 ] 
then
IND=0
###if [ $line -gt 0 ] #don't include zero events ALCARECO
###    then
    echo $line >> ${TAG}".out"
###fi
takenext=0
fi

done

mv ${TAG}".out" ../data/
#rm -f ${TAG}".tmp"