Python 3.x solução:
script diff_marked.py :
import sys
file1_name = sys.argv[1]
file2_name = sys.argv[2]
with open(file1_name, 'r') as f1, open(file2_name, 'r') as f2:
f1_lines = f1.readlines() # list of lines of File1
f2_lines = f2.readlines() # list of lines of File2
for k,l in enumerate(f1_lines):
f1_fields = l.strip().split('|') # splitting a line into fields by separator '|'
if k < len(f2_lines) and f2_lines[k]:
has_diff = False
f2_fields = f2_lines[k].strip().split('|')
for i,f in enumerate(f1_fields):
if f != f2_fields[i]: # comparing respective lines 'field-by-field' between two files
f1_fields[i] = '**' + f + '**' # wrapping differing fields
f2_fields[i] = '**' + f2_fields[i] + '**'
has_diff = True
if has_diff:
print(f1.name) # print file name
print('|'.join(f1_fields))
print(f2.name)
print('|'.join(f2_fields))
Uso: (você pode ter outra versão em python, o caso atual foi testado em python 3.5 )
python3.5 diff_marked.py File1 File2 > diff_output
diff_output
contents:
File1
1|piyush|bangalore|**dev**
File2
1|piyush|bangalore|**QA**
File1
3|rohit|**delhi**|**QA**
File2
3|rohit|**bangalore**|**dev**