I have a csv file that looks like this:
user1,400,300
user2,250,250
user3,400,300
user1,400,300
user4,400,300
user2,250,250
and a directory that has a empty file named after the user
$ ls /dir/*
/dir/user1
/dir/user2
I want to look for the file and save its name into an array, then search that name through the csv record, add all of that name's 2nd and 3rd column, for all rows, and also shows if the user value exceed ex:400
Example results:
user1,1400
user1 has exceed 400
user2,1000
user2 has exceed 400
I'd really appreciate some help. Currently I'm trying with this, but no results:
shopt -s nullglob
cd /dir/
ARRAY=(*)
for ((i=0; i<${#ARRAY[@]}; i++)); do
name=${ARRAY[i]}
awk '
BEGIN{FS=OFS=","} {$name += (($2+$3))}
END{for (j in a) printf "%s | %0.2f\n", j, a[j]}
' /dir.csv
done
cd
Or maybe is there a simpler method where no need to save filename into an array?