add second field of two files on different servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting add second field of two files on different servers
# 1  
Old 09-01-2010
Question add second field of two files on different servers

Hi

I have one file placed at one server whose sample as follows:
Code:
57272 28
56767 0
57575 4
58888 6
53030 26
54242 0
56060 0

And another file at different server whose sample data as follows:
Code:
57272 22
56767 0
57575 1
58888 2
53030 13
54242 0
56060 1

Now i want to run a script from one of the server which adds second field from both files which are not on same server and gives the output as follows:
Code:
57272 50
56767 0
57575 5
58888 8
53030 39
54242 0
56060 1

Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 09-01-2010 at 09:20 AM..
# 2  
Old 09-01-2010
As a start the processing of both files:
Code:
$> awk 'NR==FNR{_[$1]=$2; next} {print $1, _[$1]+$2}' file1 file2
57272 50
56767 0
57575 5
58888 8
53030 39
54242 0
56060 1


Last edited by zaxxon; 09-01-2010 at 09:34 AM.. Reason: a $1 too much
# 3  
Old 09-03-2010
Question add second field of two files on different servers

Hi

@zaxxon but the files are on different servers.
Please guide.

Quote:
Originally Posted by zaxxon
As a start the processing of both files:
Code:
$> awk 'NR==FNR{_[$1]=$2; next} {print $1, _[$1]+$2}' file1 file2
57272 50
56767 0
57575 5
58888 8
53030 39
54242 0
56060 1

# 4  
Old 09-03-2010
Yes, I read that. That's why I wrote "As a start...". You can copy it local with scp for example and then process both.
# 5  
Old 09-03-2010
Question add second field of two files on different servers

Hi,

@zaxxon but can we do it without copying files as copying files after every 15 minutes is somewhat not usable.

Quote:
Originally Posted by zaxxon
Yes, I read that. That's why I wrote "As a start...". You can copy it local with scp for example and then process both.
# 6  
Old 09-03-2010
Code:
ssh somehost cat /tmp/file2 | awk 'NR==FNR{_[$1]=$2; next} {print $1, _[$1]+$2}' file1 -

# 7  
Old 09-03-2010
Bug add second field of two files on different servers

Great thanks zaxxon,Thats what i wanted...Smilie

Quote:
Originally Posted by zaxxon
Code:
ssh somehost cat /tmp/file2 | awk 'NR==FNR{_[$1]=$2; next} {print $1, _[$1]+$2}' file1 -

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

2. Shell Programming and Scripting

I need to add 30 users to 50 servers

Hi Y'all, I need help adding 30 users to 50 servers. Is there a way to automate this? I'm using this command: sudo mkuser pgrp=srvadm gecos=Spears, Brittney auditclasses=ALL sugroups=system,security user01 But I'm doing it per user, per server...HOW CAN I MAKE THIS EASIER?... (7 Replies)
Discussion started by: jennie28n
7 Replies

3. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

4. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

5. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

6. Shell Programming and Scripting

Add field delimiter for the last field

I have a file with three fields and field delimiter '|' like: abc|12:13:45|123 xyz|12:87:32| qwe|54:21:09 In the file the 1st line has proper data -> abc|12:13:45|123 ,the 2nd line doesnt has data for the 3rd field which is okay , the 3rd line doesnt has data for the 3rd field as well the... (5 Replies)
Discussion started by: mehimadri
5 Replies

7. Shell Programming and Scripting

awk field equal something, then add something to the field

Hi Everyone, a.txt a b c 1 e e e e e a b c 2 e e e e e the output is a b c 1 e e e e e a 00b c 2 e e e e e when 4th field = '2', then add '00' in the front of 2nd field value. Thanks (9 Replies)
Discussion started by: jimmy_y
9 Replies

8. Shell Programming and Scripting

Merge files of differrent size with one field common in both files using awk

hi, i am facing a problem in merging two files using awk, the problem is as stated below, file1: A|B|C|D|E|F|G|H|I|1 M|N|O|P|Q|R|S|T|U|2 AA|BB|CC|DD|EE|FF|GG|HH|II|1 .... .... .... file2 : 1|Mn|op|qr (2 Replies)
Discussion started by: shashi1982
2 Replies

9. Shell Programming and Scripting

add increment field when first field changes

Hi I have a file that looks like the following: Name1 aaa bbbb Name1 ffd hhghg Name1 dffg ghhhh Name2 rtrt dfff Name2 rrtfr tgtt Name2 dsddf gfggf Name2 ffffg gfgf NAme3 fdff ghhgh Is it possible to format it so that a number... (2 Replies)
Discussion started by: azekry
2 Replies

10. Shell Programming and Scripting

User add on multiple servers

I have 85 Unix servers & I need to add single user ID on multiple servers at same time Can anyone help in this? I have written one script for single servers.same I need to user for multiple servers #!/bin/sh echo Enter user login ID read loginID echo Enter Group ID read GroupID ... (6 Replies)
Discussion started by: sandeep_pan
6 Replies
Login or Register to Ask a Question