Hi all you awk whizzos., wonder if you can help me out here, I would appreciate it immensely!
Here is a sample of my file:
12345678 23
12345678 10
33333333 1
444444444 3
444444444 6
Left column is the account number, right column is number of books.
What I am trying to do is get awk to add each account number's 2nd field together, then print the account number and total for each, i.e.
12345678 33
33333333 1
444444444 9
I have tried using the following shell script but as you can imagine, with a large(ish) file (13000 odd lines) it takes forever!!
for acct in `cut -f1 -d ' ' sort.txt|sort -u`
do
acct_total=0
set `cat sort.txt | grep $acct |cut -c12-`
while [ $# -gt 0 ]
do
acct_total=`expr $acct_total + $1`
shift 1
done
echo $acct $acct_total >> blob.txt
done
I thought I knew a little bit about awk but this one has me stumped!
Here is a sample of my file:
12345678 23
12345678 10
33333333 1
444444444 3
444444444 6
Left column is the account number, right column is number of books.
What I am trying to do is get awk to add each account number's 2nd field together, then print the account number and total for each, i.e.
12345678 33
33333333 1
444444444 9
I have tried using the following shell script but as you can imagine, with a large(ish) file (13000 odd lines) it takes forever!!
for acct in `cut -f1 -d ' ' sort.txt|sort -u`
do
acct_total=0
set `cat sort.txt | grep $acct |cut -c12-`
while [ $# -gt 0 ]
do
acct_total=`expr $acct_total + $1`
shift 1
done
echo $acct $acct_total >> blob.txt
done
I thought I knew a little bit about awk but this one has me stumped!