can anyone help me how do i add the colums using awk seperated by character @. for eg i have
3@4
2@9
5@1
the result should be
10 14
i tried using
{ sum+= $1 }
END { print sum }
but it just gives the result 10. can anyone help me with this one
thank you and best regards
nawk -F@ -f phone.awk phone.txt
phone.awk:
{
for(i=1; i<=NF; i++)
sum +=$i
}
END {
for(i=1; i in sum; i++)
printf("%s%s", sum, (i+1 in sum) ? OFS : ORS)
}
Another approach:
awk -F@ '{a[1]+=$1; a[2]+=$2} END{print a[1], a[2]}' file
Regards
i still have one question....i know both of them works...thanks a lot for that...
but is it possible to run using
awk -f filename.awk filename.txt
just curious...
thank you
filename.awk should look like this:
BEGIN{FS=OFS=" "}
{a+=$1; b+=$2} END{print a, b}
Regards
no, filename.awk should look like:
BEGIN{FS="@"}
{a+=$1; b+=$2} END{print a, b}
ya it works fine..thank u guys for the quick response.