- -, bash 4.x , , awk perl. -, : , , .
. , awk, sed perl. , , - cut, sort uniq. cut . 5-9 grep, (grep $kind stock.txt), , bash.
for kind in $(cut -d\; -f 2 stock.txt | sort | uniq) ; do
total=0
while read d ; do
total=$(( total+d ))
done < <(
while read line ; do
[[ $line =~ $kind ]] && echo $line
done < stock.txt | cut -d\; -f3
)
echo "Total amount for $kind: $total"
done
. , .
:
- , cut. stock.txt , ;, \;, . , , stock.txt. sort, uniq. "", , , .
for: , , , kind. , "Total" .
total , , .
"totaling", kind . , d in stdin .
: shell , d total.
5 while, . <, , , , read, . , , .
, while-read. while-read, line. . [[ =~, . , $line $kind.
while-read , stock.txt, , , $kind, cut , . 9 , , , kind.
, , , .