Awk addition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk addition
# 1  
Old 04-24-2011
Awk addition

How would I print out the total amount through awk? I tried using

Code:
print "Total Amount: " $4+$4;

Would I have to do a for loop to get through everything?
# 2  
Old 04-24-2011
Total amount of what? All columns?

Code:
T=0; for(N=1; N<=NF; N++) T+=$N ; printf ("total of all columns is %f\n", T);

All rows?

Code:
{ T+=$1; } END { printf("total of col 1 = %f\n", T) }

...or what?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-24-2011
I just want to print out the the total of one column. I have tried:

Code:
{ total += $4}

But it is not showing me the correct total.

---------- Post updated at 09:44 PM ---------- Previous update was at 09:43 PM ----------

Nvm I fixed it. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed or awk Replacement/Addition

Hi, I have a big text file with similar data as below and need the text as in output using awk or sed. any help is greatly appreciated. Input: City=Chicago Elden street >>> reservedBy = business 1 >>> reservedBy = business 2 >>> reservedBy = business 3 City=Dallas Elm street >>>... (5 Replies)
Discussion started by: tech_frk
5 Replies

2. Shell Programming and Scripting

Addition of new line

Hi I have a file whose contents are as follows: sorce1 LEN assumption 695 3570 0.770047 - . ID=f000001.1;source_id=A.off_LEN_10008424; sorce1 LEN descriptive 3334 3570 . - 0 Parent=f000001.1; sorce1 LEN ... (8 Replies)
Discussion started by: sa@@
8 Replies

3. Shell Programming and Scripting

AWK conditional addition

I have a column of numbers $2, I would like to add 360 to all numbers that are negative. This method seems a bit convoluted, and does not work (outputs 0): BEGIN { A=sprintf("%d", $2); if(A<0) A=A+360; BIN++; } END { for(A in BIN) print... (5 Replies)
Discussion started by: chrisjorg
5 Replies

4. Shell Programming and Scripting

Addition

Hi all, I am very new to shell programming and trying to learn out the basics. I tried this: $ echo `expr 20 + 30` and it worked. But when i tried this,it does not work. $ a=20 $ b=30 $ echo `expr a + b` The error is: expr: non-numeric argument I cant understand why its... (3 Replies)
Discussion started by: gautamshaw
3 Replies

5. Shell Programming and Scripting

Help with addition

Hi all, I am getting following output by using commands like sort, uniq and awk to the standard output. 110 d 40 a 59 c 9 b 3 e Now at the end I would like to add all the numbers in column 1 and display the count of all numbers i.e. (110 + 40 + 59 + 9 + 3). Also the output may... (3 Replies)
Discussion started by: tenderfoot
3 Replies

6. Shell Programming and Scripting

date addition

i have a script called date_add.sh written in k_shell My shell script requirement is that it accepts a date from the user in the format YYYY-MM-DD and then it shows all the 15 days later day availaible in the current year if date accepted from user is 2008-10-13,then the o/p sholud be... (5 Replies)
Discussion started by: ali560045
5 Replies

7. UNIX for Dummies Questions & Answers

addition in sh shell

I have to create un counter and I am unable to do an additition: #!/bin/sh count=$1 while ] do echo $count $count=$count+$1 done (1 Reply)
Discussion started by: cfg
1 Replies

8. Shell Programming and Scripting

Simple addition, help.

I add up the number of args that are not blank. It works, but the printout is a string that just keep concatenating on +1. So Ex. it goes through input of: bob toto " " tom ...I get 0+1+1+1, when all I want is 3. Any help is appreciated. count=0 for name in $* do if ; then ... (3 Replies)
Discussion started by: Bandit390
3 Replies

9. Shell Programming and Scripting

addition

Hi all, I am new to perl. I need help adding bunch of numbers. I have a file look like this: 1 1 2 1 2 3 1 2 3 4 1 (2 Replies)
Discussion started by: email-lalit
2 Replies

10. Shell Programming and Scripting

Addition problem

Hello Seniors!!! I am trying to add to lines on a file which is delimited by character "|". input.txt Desired Output file should give simple addition. output.txt Can some one provide me simple awk solution to this. M struggling to solve this using awk & for loop inside awk. Thanks... (2 Replies)
Discussion started by: onlyroshni
2 Replies
Login or Register to Ask a Question