How can I read one line at a time with C shell in unix

I am trying to make a small script using c shell, which will take a file of several lines, each of which contains a name and a number and summarizes all numbers that have a specific name. How can I add the following line to a variable each time?

the summig part I am doing: (after I can get the full line up to the $ line)

set line =($line)
@ sum = $sum + $line[2]
+5
source share
3 answers

I managed to solve it using the following code snippet:

foreach line ("`grep $1 bank`")
    echo $line
    set line_break = ($line)
   @ sum = $sum +$line_break[2]
end
echo $1\ balance id: $sum\$
+6
source

I found this discussion that could answer your question: http://www.linuxquestions.org/questions/programming-9/csh-while-read-738708/

+1

Awk :

% cat >test.dat
a 1
a 3
b 2
a 7
b 4
% awk '($1 == "a") { SUM += $2 } END { print SUM }' < test.dat
11
-1

All Articles