I'm stuck at figuring out how to sum ls
5th column result with awk
. If I add $bytesum+=...
then the program obviously breaks.
Any ideas?
bytesum=0
for i in `cat fileextensions.txt | sort | uniq`
do
ls -Rl "$folder" | grep $i | awk '{bytesum+=$5}; {print $9 " " $5}'
done
echo $bytesum
sort | uniq
=sort -u
andgrep foo | awk '{bar}'
=awk '/foo/{bar}'
and you don't need separate blocks for every action in awk -{x}; {y}
={x; y}
andprint $9 " " $5
=print $9, $5
(it's why OFS exists). And where did$folder
come from? – Ed Morton Apr 10 '20 at 12:54$folder
is a path to the folder where the script recursively searches for files with given extensions. – gici Apr 10 '20 at 13:11fileextensions.txt
and do you really need that as a file? – Kusalananda Apr 10 '20 at 14:39