Need to total numbers at end of script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to total numbers at end of script
# 1  
Old 09-22-2006
Question Need to total numbers at end of script

I need to total the numbers at the end of script, what code can i use for this to total the lines up?

1232
1242
1234

Total count is 3708
# 2  
Old 09-22-2006
Code:
echo "1232+1242+1234" | bc

# 3  
Old 09-22-2006
How can i add the number output to create a total

What do i use if i get different numbers each time i run the script? Can I use echo "12345678910" | bc? will this count any amount of numbers then give a total?

cat $MYHOME/hcscprod_job_totals |wc -l
cat $MYHOME/hcncprod_job_totals |wc -l
cat $MYHOME/ktazp_job_totals |wc -l
cat $MYHOME/ktazd_job_totals |wc -l
cat $MYHOME/ktazi_job_totals |wc -l

2843
1592
3351
2776
1200

Last edited by wereyou; 09-22-2006 at 06:13 PM.. Reason: script output
# 4  
Old 09-22-2006
Code:
awk ' { x = x + int($0) } END { print "Total count is " x }' no_file

# 5  
Old 09-22-2006
i am gettting this error:

2888
1604
3425
2785
1200
awk: 0602-533 Cannot find or open file no_file.
The source line number is 1.
# 6  
Old 09-22-2006
Code:
cat $MYHOME/hcscprod_job_totals |wc -l > no_file
cat $MYHOME/hcncprod_job_totals |wc -l >> no_file
cat $MYHOME/ktazp_job_totals |wc -l >> no_file
cat $MYHOME/ktazd_job_totals |wc -l >> no_file
cat $MYHOME/ktazi_job_totals |wc -l >> no_file

awk ' { x = x + int($0) } END { print "Total count is " x }' no_file

# 7  
Old 09-22-2006
The command cat is useless, wc accept filename(s) as argument :
Code:
wc -l $MYHOME/hcscprod_job_totals

You can avoid the usage of a temporary file, for example :
Code:
wc -l $MYHOME/hcscprod_job_\
        $MYHOME/totals hcncprod_job_totals \
        $MYHOME/ktazp_job_totals \ 
        $MYHOME/ktazd_job_totals \
        $MYHOME/ktazi_job_totals |
awk ' { x = x + int($0) } END { print "Total count is " x }'


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching range of filenames witn and without numbers on the end

So I'm grepping for the following right now: ls -la /somedirectory/*.log* | awk '{print $9}' The problem with this is that I get the following output: /somedirectory/errors_1_foo.log /somedirectory/errors_1_foo.log.1 /somedirectory/errors_1_foo.log.2... (4 Replies)
Discussion started by: LinuxRacr
4 Replies

2. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

3. Shell Programming and Scripting

Using awk to append incremental numbers to the end of duplicate file names.

I'm currently working on a script that extracts files from a .zip, runs an sha1sum against them and then uses awk to pre-format them into zomething more readable thusly: Z 69 89e013b0d8aa2f9a79fcec4f2d71c6a469222c07 File1 Z 69 6c3aea28ce22b495e68e022a1578204a9de908ed File2 Z 69... (5 Replies)
Discussion started by: Ethereal
5 Replies

4. Shell Programming and Scripting

Generate Codes based on start and End values of numbers in a column

Hello All, Could you please help with this. This is what I have: 506234.222 2 506234.222 2 506234.222 2 506234.222 2 508212.200 2 508212.200 2 333456.111 2 333456.111 2 333456.111 2 333456.111 2 But this is what I want: 506234.222 1 506234.222 2 506234.222 2 506234.222 3 (5 Replies)
Discussion started by: canimba
5 Replies

5. Shell Programming and Scripting

Adding patterns with increasing numbers at the end of every line

Hi All, I have a file which has some Linux commands in every line like more 456.dat more 3232.dat more 433.dat I want to add texts like this at the end of every line: more 456.dat > 1.txt more 3232.dat > 2.txt more 433.dat > 3.txt So, that the result of more goes into 1.txt... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

Use of Begin IF ,END IF END not working in the sql script

Hi I have written a script .The script runs properly if i write sql queries .But if i use PLSQL commands of BEGIN if end if , end ,then on running the script the comamds are getting printed on the prompt . Ex :temp.sql After connecting to the databse at the sql prompt i type... (1 Reply)
Discussion started by: isha_1
1 Replies

7. Shell Programming and Scripting

awk is Printing folders with only numbers as expected. But can't explain 'total' statement.

I am trying to get folder names that contain only numbers. Can someone explain why following command is printing 'total 450' as part of output.. $> ls -lt | awk '$9 ~ /^*$/' | more total 450 drwxr-x--x 3 user1 group1 512 Mar 9 2008 329227163 drwxr-x--x 3 user1 group1 ... (17 Replies)
Discussion started by: kchinnam
17 Replies

8. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

9. Solaris

Need help capturing end of line numbers

Hello All, Currently I am attempting to write a script which will capture a number at the end of a line. The line which I am searching through ends as follows: word word=number for example word word=3 OR word word=15 I am stuck on how to capture whatever is to the right... (3 Replies)
Discussion started by: icalderus
3 Replies
Login or Register to Ask a Question