How To Add Numeric Data of A file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How To Add Numeric Data of A file
# 1  
Old 03-17-2007
How To Add Numeric Data of A file

Dear All,
I want to add Numeric data of my file called temp_f41. But I am not getting how to add them,

My File data are in following format of:
10
39
53
05
37
54

Plz send me code for this
Thanks
Nishant Smilie
# 2  
Old 03-17-2007
Code:
$ cat data
10
39
53
05
37
54
$ awk '{ t=t+$1 } END {print "total = ", t}' data
total =  198
$

# 3  
Old 03-17-2007
Code:
c=0
for i in `tr '\n' ' ' < file`; do c=`echo "$c + $i" | bc`   ;done #or use c=$((c+i))
echo $c

# 4  
Old 03-17-2007
Quote:
Originally Posted by krishna_sicsr
Dear All,
I want to add Numeric data of my file called temp_f41. But I am not getting how to add them,

My File data are in following format of:
10
39
53
05
37
54

Code:
printf "%d\n" $(( $(tr '\012' '+' < temp_f41) 0 ))

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a numeric & special char to end of the first line

Need to add a numeric & special char to end of the first line Existing file: 12-11-16|11 2016 Jan 12:34:55|03:55| 13-10-16|10 2016 Jan 12:34:55|03:55|12-11-16|11 2016 Jan 12:34:55|03:55| 14-10-16|19 2016 Jan 12:34:55|03:55|13-11-16|11 2016 Jan 12:34:55|04:55| 15-10-16|18 2016 Jan... (11 Replies)
Discussion started by: Joselouis
11 Replies

2. Shell Programming and Scripting

Help with add existing file name as new data column in new output file

Input File 1 cat S1.txt MI0043 2731 miR-1 Input File 2 cat S4.txt MI006 310 CiR-1 MI057 10 CiR-24 MI750 5 CiR-24 Desired Output File 1 cat S1.txt.out MI0043 2731 miR-1 S1.txt Desired Output File 2 cat S4.txt.out MI006 310 CiR-1 S4.txt (3 Replies)
Discussion started by: perl_beginner
3 Replies

3. Shell Programming and Scripting

Add edited numeric strings in awk

I am using awk to sum up all amounts and at end print total. input: 10,250.00 20,103.15 expected output: 30353.15 code: {subtot=+$1} END{print subtot} The problem I encounter is it stops at commas and returns 30 as answer And if I use this code: {subtot=($1+0);subtot=+$1}... (9 Replies)
Discussion started by: paresh n doshi
9 Replies

4. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

5. Shell Programming and Scripting

add more data to existing data in a file

Hi all, I need help to add additional data from file2 to existing data in file 1 using awk, sed or perl. the ID in file 1 should match against field $3 in file2 file1 #this is a new game ID HR_1 BASE1 30 BASE2 37 DETAIL No TYPE L @@ ID HR_10 BASE1 6030 BASE2 ... (4 Replies)
Discussion started by: redse171
4 Replies

6. Shell Programming and Scripting

Perl script to sort data on second numeric field

Hi, I'm a learner of PERL programming. I've a input file with the below data: SWAT_5, 1703, 2010-09-21 SWAT_6, 2345, 2010-09-21 SWAT_7, 1792, 2010-09-21 SWAT_8, 1662, 2010-09-21 SWAT_9, 1888, 2010-09-21 VXHARP_1, 171, 2010-09-21 I need to sort this data based on the second... (6 Replies)
Discussion started by: ganapati
6 Replies

7. UNIX for Dummies Questions & Answers

Find and Replace random numeric value with non-numeric value

Can someone tell me how to change the first column in a very large 17k line file from a random 10 digit numeric value to a non numeric value. The format of lines in the file is: 1702938475,SNU022,201004 the first 10 numbers always begin with 170 (6 Replies)
Discussion started by: Bahf1s
6 Replies

8. Shell Programming and Scripting

add data into a file

I have a csv file, i need to insert data into csv file at row 6 If row 6 in csv file is emplty then i need to enter s23, if row 6 in csv file has some value in it then i don't have to do any thing. and i have 100 csv files and and each csv files has 45000 rows of data in it. (1 Reply)
Discussion started by: gaddamshashank
1 Replies

9. Shell Programming and Scripting

Perl code to differentiate numeric and non-numeric input

Hi All, Is there any code in Perl which can differentiate between numeric and non-numeric input? (11 Replies)
Discussion started by: Raynon
11 Replies

10. Shell Programming and Scripting

How to check a column contain numeric or char data type ??

I have a file called clientname_filename.csv whose contents are like col1|col2|col3|col4| 510|abc|xxx|450| 510|abc11|yyy|350 510|pqr99|zzz| 670 512|222|439|110 Here i have check the contents of column for data type. i have a constraints that col1 always contain Numeric value column 2... (12 Replies)
Discussion started by: jambesh
12 Replies
Login or Register to Ask a Question