0

how can I get the array values from the variable emailFailures. please help me on this. Thank you.

#!/bin/ksh
MY_WORK='/a585/app/data/CCN_text'
raw_data_file_count=`ls -l raw_data_*|wc -l`
echo " $raw_data_file_count"


ls -l raw_data_* | awk -F" " '{print $9}' | awk -F"_" '{print $3}' > file_counter.txt

while read line
do

counter_array+=("$line")

done < file_counter.txt


raw_data_file_counter_length=${#counter_array[@]}

echo "ARRAY LENGTH : ${raw_data_file_counter_length}"

reccount=0
for ((count=0; count<raw_data_file_counter_length; count++));
do

    echo " COUNTER VALUE: ${counter_array[$count]} "

    emailFailures=("$(grep 'emailCountFailure' $MY_WORK/raw_data_${counter_array[$count]} | awk -F'=' '{print $2}' )" )


done

for t in "${emailFailures[@]}"
do 
    echo "      "$t 
done
  • 1
    Please edit and provide MCVE. State clearly what the result is, what you expect, what the problem is. Is the content of file_counter.txt what you expect in the first place. I'm asking because one shouldn't parse ls. I see other obscurities in your code, maybe because I don't get what you're trying to do (that's why there is M in MCVE). Maybe the whole procedure can be rebuilt in a better way, maybe not; but parsing ls is IMO the first thing to audit here and get rid of. – Kamil Maciorowski Feb 21 at 12:44
  • Looks like the whole script could be replaced with a single awk: awk -F= '/emailCountFailure/{print $2}' "$MY_WORK"/raw_data_?* – user1139593 Feb 21 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.