mercredi 20 novembre 2019

Getting data from an array and applying if condition

I am stuck here as i read data from a csv file and stored in an array Now i want to display the data based on the condition

file_csv="ports.csv"
index=0
while IFS= read -r line;do
        array["$index"]="$line"
        index=$(($index + 1));
done < $file_csv

for lines in "${array[@]}"
do
        #echo $(awk '/down/ {print}' | sed -n 's/HUAWEI//' <<< $index )
        if [[ ${array[@]}=="down"  ]]; then
                echo  "found $index" | sed 's/Huawei/d/'
        fi

done

a=$(awk '/down/ {print}' $file_csv)

Output required

Interface down down Summary

Aucun commentaire:

Enregistrer un commentaire