I have a task for university to create 5 folders, 10 files inside of each of them, then randomly generate 10 numbers inside all the files and finally calculate the sum of numbers in files of each folder and output them to a separate file. We only learned the basics of basics and it's really hard for me to understand what to do next. I have managed to create the folders and files with random numbers inside but I don't know how to go through every folder and sum the numbers in each file. Can someone please help me with that?
#!/bin/bash
mkdir Katalogas1
mkdir Katalogas2
mkdir Katalogas3
mkdir Katalogas4
mkdir Katalogas5
for x in {1..10}
for x in {1..10}
do
touch "$x.txt"
shuf -i1-1000 -n 1 >Katalogas1/$x.txt
done
paste 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt >bendras1.txt
cat bendras1.txt | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,($1+$2+$3+$4+$5+$6+$7+$8+$9+$10)}' >katalogas1.txt
cd ..
cd Katalogas2
for x in {1..10}
do
touch "$x.txt"
shuf -i1-1000 -n 1 >Katalogas2/$x.txt
done
paste 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt >bendras2.txt
cat bendras2.txt | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,($1+$2+$3+$4+$5+$6+$7+$8+$9+$10)}' >katalogas2.txt
cd ..
cd Katalogas3
for x in {1..10}
do
touch "$x.txt"
shuf -i1-1000 -n 1 >Katalogas3/$x.txt
done
paste 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt >bendras3.txt
cat bendras3.txt | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,($1+$2+$3+$4+$5+$6+$7+$8+$9+$10)}' >katalogas3.txt
cd ..
cd Katalogas4
for x in {1..10}
do
touch "$x.txt"
shuf -i1-1000 -n 1 >Katalogas4/$x.txt
done
paste 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt >bendras4.txt
cat bendras4.txt | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,($1+$2+$3+$4+$5+$6+$7+$8+$9+$10)}' >katalogas4.txt
cd ..
cd Katalogas5
for x in {1..10}
do
touch "$x.txt"
shuf -i1-1000 -n 1 >Katalogas5/$x.txt
done
paste 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt >bendras5.txt
cat bendras5.txt | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,($1+$2+$3+$4+$5+$6+$7+$8+$9+$10)}' >katalogas5.txt