Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have to compare two files, file1 and file2. Each file has 56 columns separated by |. First column is the employee number in the file, I will check whether same employee number is present in the second file or not. If not we will write the whole row to the output file. If same employee number is present in the file2, I need to compare value of each column. If data doesn't match, we have to write it to the output file. If values of each column match then we need to omit that record.

Sample File
File 1

2620|256034|131021|Mission Quality and Wipro Way|||
2622|256034|131021|Mission Quality and Wipro Way|||
2623|256034|131021|Mission Quality and Wipro Way|||

File 2

2620|256034|234567|Mission Quality and Wipro Way|||
2621|256034|131021|Mission Quality and Wipro Way|||
2622|256034|131021|Mission Quality|||
2623|256034|131021|Mission Quality and Wipro Way|||

Sample Output:

2620|256034|131021|Mission Quality and Wipro Way|||
2621|256034|131021|Mission Quality and Wipro Way|||
2622|256034|131021|Mission Quality|||
share|improve this question

2 Answers 2

If files are sorted much easy do the task by diff

comm -13 File1 File2
share|improve this answer
    
Can you please share a sample script for doing this. –  Biswamohan Padhy Dec 26 at 13:50
    
@BiswamohanPadhy I've take samples in your question. –  Costas Dec 26 at 13:58

You could use awk e.g.

awk -F'|' 'NR==FNR {a[$1]=$0;next;}; !($1 in a) || ($0 != a[$1]);' File1 File2

Using your example File1 and File2

$ awk -F'|' 'NR==FNR {a[$1]=$0;next;}; !($1 in a) || ($0 != a[$1]);' File1 File2
2620|256034|234567|Mission Quality and Wipro Way|||
2621|256034|131021|Mission Quality and Wipro Way|||
2622|256034|131021|Mission Quality|||
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.