How to sum 2 files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sum 2 files?
# 1  
Old 09-30-2010
How to sum 2 files?

i have arq1.txt , like this:

1
2
3
4
5

and another arq2.txt

1
2
3
4
5

how to make this:

2
4
6
8
10

thks !
regrads

Last edited by beandj; 09-30-2010 at 04:18 PM..
# 2  
Old 09-30-2010
Hello.

Per our forum rules, all posts must be in English.

We do provide translation services for posts from English to a number of languages as a benefit to users. However, posts must be in English.

Please repost in English.

Thank you for your cooperation.

The UNIX and Linux Forums.
# 3  
Old 09-30-2010
sorryy

i will repost it
# 4  
Old 10-01-2010
Code:
paste arq1.txt arq2.txt | awk '{ print ($1 + $2) }'

# 5  
Old 10-01-2010
Code:
awk '{t=$1;getline<"arg1.txt";print t+$1}' arg2.txt

# 6  
Old 10-01-2010
Code:
awk 'getline x<f{print $1+x}' f=arq1.txt arq2.txt

Code:
awk 'getline x<f{$1+=x}1' f=arq1.txt arq2.txt


Last edited by Scrutinizer; 10-01-2010 at 05:49 AM..
# 7  
Old 10-01-2010
Code:
# ruby -ne 'BEGIN{a=File.read("file1").split("\n").map(&:to_i)}; puts $_.chomp.to_i + a[$.-1]' file2
2
4
6
8
10

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get CRC check sum of files in java EAR file without extracting .jar/.war files to disk.?

unzip -v gives CRC info of each file in a zip(in my case .EAR) file. # unzip -v my-application.ear Archive: my-application.ear Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 197981 Defl:N 183708 7%... (1 Reply)
Discussion started by: kchinnam
1 Replies

2. Shell Programming and Scripting

Sum of numbers in three or more files

I have files : cat file1 15 88 44 667 33 4cat file2 445 66 77 3 56 (12 Replies)
Discussion started by: Natalie
12 Replies

3. Shell Programming and Scripting

Sum fields of different files using awk

I'm trying to sum each field of the second column over many different files. For example: file1: file2: 1 5 1 5 2 6 2 4 3 5 3 3 To get: file3 1 10 2 10 3 8 I found answer when there are only 2 files as... (10 Replies)
Discussion started by: rogeriog.em
10 Replies

4. Shell Programming and Scripting

sum numbers of multiple files

Hi, I want to count the number of occurrences of numbers from a file of 6,000,000 lines. Because its too large, I decided to split the counts up in multiple files. So I have files of the counts of 5,000 lines. Now I want to add up the counts of all those files. The "counts file" looks like... (9 Replies)
Discussion started by: linseyr
9 Replies

5. Shell Programming and Scripting

Sum Numbers from different files

Hi All, I need to print the sum of numbers from different files. Input files: file1.out 10 20 30 file2.out 10 20 30 (5 Replies)
Discussion started by: saint2006
5 Replies

6. Shell Programming and Scripting

sum the columns of files

I have several csv files like this: file1.csv 1 12 1 2 8 9 3 9 2 4 5 9 ... file2.csv 1 0 1 2 2 3 3 4 1 ... file3.csv 1 0 1 2 4 0 ... I want the result like this 1 12 3 2 14 12 3 13 3 (10 Replies)
Discussion started by: frewise
10 Replies

7. Shell Programming and Scripting

Parsing and sum column from different files

Hy everybody, I have three file with the same formating. I need to parse those files in order that for each first column of the first file, sum the second columns of first,second and third files. Can someone help me ? example : # more file1 00:00:12,137;7,0333333 # more file2... (6 Replies)
Discussion started by: robdcb
6 Replies

8. Shell Programming and Scripting

SUM of Backup Files

Hello Everyone, I'm struggiling with backup issues and need to sum up sizes of backup files monthly and add the result to the next month's sum recursively. For this i have a well working script that i modified as i showed below and this part gives the sum of the file sizes under working... (2 Replies)
Discussion started by: EAGL€
2 Replies

9. Shell Programming and Scripting

how to sum values from 2 different files?

Hi I am trying to add count values from two different files into one file. Could any body please suggest me best command to do this? My problem was as follows: a.txt b.txt c.txt 10 20 30(needed) i tried cat a.txt b.txt > c.txt (its not adding the values) Thanks in advance.. Praveen (8 Replies)
Discussion started by: npk2210
8 Replies

10. Shell Programming and Scripting

sum numbers in multiple files

I have 11 directories with around 200 files in each. In each directory the files are labeled out.0 through out.201 . Each file has around 118 numbers in a single column. I need to sum the files in each directory so each directory will have a resultant vector that is 118 numbers long. I then... (5 Replies)
Discussion started by: pattywac
5 Replies
Login or Register to Ask a Question