Compare files and share output from both files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare files and share output from both files
# 1  
Old 10-25-2013
Linux Compare files and share output from both files

hi all,

Thanks to all for your great help...

I have a scenario that I have two files (file1 & file2). I need to compare two files entire row by row and share the output if any discrepancies within two files.

File1:

Code:
DB1|TB1|C1,C3
DB2|TB2|C1,C2
DB3|TB3|C1,C2,C3,C4


File2:

Code:
DB1|TB1|C1,C2,C3
DB2|TB2|C1,C2
DB3|TB3|C1,C3
DB4|TB4|C1,C2,C4

Output should be:
Code:
DB1|TB1|C2  --email content should be "missing in file1 or new column added in file2
DB3|TB3|C2,C4 -- email content "remove C4,C2 from file 1" 
DB4|TB4|C1,C2,C4  -- missing in file1


IN short, we need to compare two files and share difference/missing items from these two files. Comparison should be ROW by ROW.

Last edited by Don Cragun; 10-25-2013 at 12:55 AM.. Reason: Add CODE tags.
# 2  
Old 10-25-2013
You explained your problem quite inconsistently, so a few questions first:

I take it your files are of the form

Code:
key,value

where "key" is something like "DB1|TB1|" and "value" is everything after that. You search for every of these keys, compare the differences in the corresponding "value"s and record these differences, yes?

If so: can there be more than one line for each key in each file? i.e.

file1
Code:
DB1|TB1|C1,C2

file2
Code:
DB1|TB1|C1
DB1|TB1|C2

and would this result in "no difference" or in something else?

Then, are the entries in "value" all separated by commas and can that be used consistently as a delimiter?

bakunin
# 3  
Old 10-28-2013
Thanks for your response.

The requirement is to compare two files (which has "database name"|"Tablename"|"Column1,column2,column3") in this pattern, but there might be a mismatch in number of columns in any one of the file..

Output should be like the missing column names should get displayed with respective db & tables.

File 1
Code:
database1|table1|column1,column2,column3
database2|table2|column1,column3
database3|table3|column1,column2,column3,column4

File 2:
Code:
database1|table1|column1,column3
database2|table2|column1,column2,column3
database3|table3|column1,column3,column4

if any column name is missing in any one of the file for the database|table names, then it should display the changes by stating both file contents (db|tab|column names) and send an email.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To compare two files,Output into a new file

Hi Please help me to compare two files and output into a new file file1.txt 15114933 |4001 15291649 |933502 15764675 |4316 15764678 |4316 15761974 |282501 15673104 |933505 15673577 |933505 15673098 |933505 15673096 |933505 15673092 |933505 15760705 ... (13 Replies)
Discussion started by: Ankita Talukdar
13 Replies

2. UNIX for Dummies Questions & Answers

Compare two files and output to new file

Hi, Please help How to compare two files- Any mismatches 2nd and 3rd column's values corresponding to 1st column. file1 15294024|Not Allowed|null 15291398|Not Allowed|null 15303292|Dropship (standard)|N 15303291|Dropship (standard)|N 15275561|Store Only|Y 15275560|Store Only|Y... (2 Replies)
Discussion started by: Ankita Talukdar
2 Replies

3. Shell Programming and Scripting

Compare two files and output in another file

I have two files ' 1st one ALIC-000352-B ALIC-000916-O DDS-STNGD FDH-PPO1-001 PFG-30601-001 2nd one 'ALIC-000352-B' 'ALIC-000916-O' 'DDS-STNGD' 'FDH-PPO1-001' (4 Replies)
Discussion started by: Pratik4891
4 Replies

4. Shell Programming and Scripting

Compare two files in different formats and get output

File A: DATAFILE TABLESPACE ------------------------- ------------------------- /dev/rprod_0032_011 D_EEM /dev/rprod_0032_012 D_ESO_REF ... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

5. Shell Programming and Scripting

Compare 2 files and output only the different text.

I know the diff does this but it does output more info than just the different text (e.g. $ diff file1 file2 29a30 > /home/alex/Pictures/hello.jpg 1694a1696 > /home/alex/Pictures/hi.jpg ) How can I make it output only /home/alex/Pictures/hello.jpg /home/alex/Pictures/hi.jpg ? thank... (2 Replies)
Discussion started by: hakermania
2 Replies

6. Shell Programming and Scripting

Compare two files and get output

Hi, I have two files, file1 and file2 and I need to compare them by line (exact match, order of the lines is not important) and get output with lines from file2 that are not found in file1 (not other way around). How do I do that? With grep or otherwise.. Thankyou (2 Replies)
Discussion started by: orp56
2 Replies

7. Shell Programming and Scripting

compare files in two directories and output changed files to third directory

I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together. I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Discussion started by: bkeep
4 Replies

8. Shell Programming and Scripting

compare 2 files > output new to third

Hi, I have a question of comparing to files and output the result third file where file1 is the mainfile containing processed dir data and 2nd file grepīs dirīs data again (could be newer dirs comparing file1<file2) now i wanna make shure that output in file3 only contains newer dirs hx... (1 Reply)
Discussion started by: needle
1 Replies

9. Shell Programming and Scripting

Compare 2 files and send output to other

Hi, In File1.txt I have text like: 23AA3424DD23|3423ff25sd5345| and so on In File2.txt I have similar text as File1, but with ",": 23aa3424dd23,192.168.1.100, and so on I wan to remove the pipes from File1 and select 5 fields, then remove "," from File2.txt and select 2 fields (IP's... (14 Replies)
Discussion started by: cameleon
14 Replies

10. UNIX for Dummies Questions & Answers

Compare Files and Output Difference

I have to compare two files for any differences, then output the lab and question number for any differences. This is what I currently have: diff lab2.txt lab2answer.txt > lab2compare.txt Though the output doesn't have to be sent to a .txt (or any sort of log), I found that easier, at least... (2 Replies)
Discussion started by: Joesgrrrl
2 Replies
Login or Register to Ask a Question