script needed to merge two files and report differences


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script needed to merge two files and report differences
# 1  
Old 03-07-2009
script needed to merge two files and report differences

Hello,

I have two txt files that look like this:

db.0.0.0.0:
Total number of NS records = 1


db.127.0.0.0:
Total number of NS records = 1
Total number of PTR records = 1


db.172.19.0.0:
Total number of NS records = 1
Total number of PTR records = 3


db.172.19.59.0:
Total number of NS records = 1
Total number of PTR records = 1

I would first like to merge two of them together side by side and at the end count from each on what is different and what matches and report:

For example the report could look like this side by side:

File A:
db.172.19.59.0
Total number of NS records = 1
Total number of PTR records = 1

File B
db.172.19.59.0
Total number of NS records = 1
Total number of PTR records = 1

And where there is a difference:

File A:
db.172.19.59.0
Total number of NS records = 100
Total number of PTR records = 23

File B
db.172.19.59.0
Total number of NS records = 101
Total number of PTR records = 26

Can this be done with Awk or Perl?

Thanks in advance !




was
# 2  
Old 03-08-2009
Hi, I am working with this:

$ perl -00ne 'push @a,"$_\0$ARGV\n";END{print reverse split/\0/ for sort @a}' fileA.txt fileB.txt

But it wont give me side by side(left and right) its showing up/down

File A:
db.172.19.59.0
Total number of NS records = 1
Total number of PTR records = 1

File B
db.172.19.59.0
Total number of NS records = 1
Total number of PTR records = 1

And where there is a difference:

File A:
db.172.19.59.0
Total number of NS records = 100
Total number of PTR records = 23

File B
db.172.19.59.0
Total number of NS records = 101
Total number of PTR records = 26

any ideas or a better way?
# 3  
Old 03-09-2009
Does this appear too complicated to accomplish?
# 4  
Old 03-09-2009
Question

Have you looked into?

diff command

comm command
# 5  
Old 03-09-2009
Code:
Yea, but its not pretty. Just want to have it side by side, Will diff take the above file and 

Put it like this?


Hi, I am working with this:

$ perl -00ne 'push @a,"$_\0$ARGV\n";END{print reverse split/\0/ for sort @a}' fileA.txt fileB.txt

But it wont give me side by side(left and right) its showing up/down

File A:                                                             File B
db.172.19.59.0                                                db.172.19.59.0
Total number of NS records = 1                        Total number of NS records = 1
Total number of PTR records = 1                      Total number of PTR records = 1



And where there is a difference:

File A:                                                           File B
db.172.19.59.0                                              db.172.19.59.0
Total number of NS records = 100                  Total number of NS records = 101
Total number of PTR records = 23                  Total number of PTR records = 26


any ideas or a better way?


Last edited by richsark; 03-09-2009 at 04:22 PM..
# 6  
Old 03-09-2009
I tried to put this side/by side, but when I post it, I loose format
# 7  
Old 03-09-2009
Hammer & Screwdriver

After you paste something with definite positioning, highlight your text and then click on the # sign above for the smart-icon. The will put code-tags around your message and keep from reformatting and wrapping.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to Compare Files and Email the differences

Hi, I have 2 files abc.txt and bdc.txt. I am using $diff -y abc.txt bcd.txt -- compared the files side by side I would like to write a Shell Script to cmpare the files side by side and print the results( which are not matched) in a side by side format and save the results in another... (10 Replies)
Discussion started by: vasuvv
10 Replies

2. Shell Programming and Scripting

script to merge two files on an index

I have a need to merge two files on the value of an index column. input file 1 id filePath MDL_NUMBER 1 MFCD00008104.mol MFCD00008104 2 MFCD00012849.mol MFCD00012849 3 MFCD00037597.mol MFCD00037597 4 MFCD00064558.mol MFCD00064558 5 MFCD00064559.mol MFCD00064559 input file 2 ... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

3. Shell Programming and Scripting

Clearcase ucm baseline differences report in xls format

Hi All, Can any one help me to get the shell/perl scripts for the below requirements. 1: To get the clearcase checkin's information between two lables generate a formatted Xls output and to find the added changed and removed files and versions between the ClearCase baselines. 2... (2 Replies)
Discussion started by: saku
2 Replies

4. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

5. Shell Programming and Scripting

merge two files via looping script

Hi all, I hope you can help me. I got a file a and a file b File a contains a b c d e f g h File b contains 1 2 3 (8 Replies)
Discussion started by: stinkefisch
8 Replies

6. Shell Programming and Scripting

Help needed to validate and merge Two files

Hi.. I am new to unix !!! Please help me in combining two files by validating the first column. The files are tab limited !!! I have a file which has the following contents... DEPT1_BABYCARE 20 abce DEPT2_PHARMACY 50 cdgde DEPT3_WOMENS ... (7 Replies)
Discussion started by: ashokrajaa
7 Replies

7. Shell Programming and Scripting

script to merge xml files with options

Hi, I have a very basic knowledge of shell scripting & would like some help with a little problem I have. I sometimes use a program calle phronix & sometimes like to compare its results which are *.xml files. Which is easy enough but a friend wants to avoid typing the path to the files.... (2 Replies)
Discussion started by: ptrbee
2 Replies

8. Shell Programming and Scripting

Merge two files in windows using perl script

Hi I want to merge two or more files using perl in windows only(Just like Paste command in Unix script) . How can i do this.Is ther any single command to do this? Thanks Kunal (1 Reply)
Discussion started by: kunal_dixit
1 Replies

9. Shell Programming and Scripting

Script needed to FTP a file from sql report to unix server

Hi All, I have a Sqlplus report which will create a file. I need a FTP Script that will be executed inside the Sqlplus Report to FTP the report output file to unix server. Thanks, Previn (0 Replies)
Discussion started by: vprevin
0 Replies

10. Shell Programming and Scripting

shell script to merge files

Can anybody help me out with this problem " a shell program that takes one or any number of file names as input; sorts the lines of each file in ascending order and displays the non blank lines of each sorted file and merge them as one combined sorted file. The program generates an error... (1 Reply)
Discussion started by: arya
1 Replies
Login or Register to Ask a Question