Hi All,
I am currently trying to do the below requirement.
Navigate to one specific directory and search one pattern from a group of files in the directory and store the count of occurence in an array. Now from the array i need to get the name of the file which had this occurence.
Code:
declare -a merchantName=('merchant1' 'merchant2' 'merchant3' )
declare -a cb
bm=25
dt=$(date --date="3 days ago" +"%Y""%m""%d")
tLen=${#merchantName[@]}
for (( i=0; i<${tLen}; i++ ));
do
cb=($(find /home/user/bhw/ -type f -name "file_feed_*${merchantName[$i]}*_${dt}*.gz.out" -exec grep -i "record" {} + | wc -l))
if (( ${cb[i]} > ${bm} )); then
echo ${merchantName[$i]}
fi
done
When running the above code getting the exception as
bhw.sh: line 50: > 25 : syntax error: operand expected (error token is "> 25 ")
But if i am pre declaring the count of occurence into each array element script works fine,like as highlighted .
Code:
declare -a merchantName=('merchant1' 'merchant2' 'merchant3' )
declare -a cb
bm=25
dt=$(date --date="3 days ago" +"%Y""%m""%d")
tLen=${#merchantName[@]}
for (( i=0; i<${tLen}; i++ ));
do
cb=($(find /home/user/bhw/ -type f -name "file_feed_*${merchantName[$i]}*_${dt}*.gz.out" -exec grep -i "record" {} + | wc -l))
cb[0]=0
cb[1]=256
cb[2]=0
if (( ${cb[i]} > ${bm} )); then
echo ${merchantName[$i]}
fi
done
Please let know if the requirement is clear and how to resolve the exception.