'How to make an alias that will sum a column of a file in my cshrc

I was wondering how I can make an alias in my .cshrc that will sum a column of my choosing of a file that I give it.

for example: if text.txt was:

a b 3
a c 2
b c 1
sumcolumn 3 text.txt

would return 6

I think that I can use !:1 and !:2 for my user inputs right?

Here is what I am trying right now:

alias sumcolumn "awk \'{SUM+=\$\!:1}END{print SUM}\' \!:2"

I think I am not escaping something correctly. When I source my .cshrc I get a error:

Variable name must contain alphanumeric characters.

I have already manually tried using the awk command in the shell:

awk '{SUM+=$3}END{print SUM}' test.txt

and it works. What am I missing?



Solution 1:[1]

alias sumcolumn 'awk '\''{ k += $3 }END{print k}'\'''

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pankaj