I got a requirement where I need to compare two files wrt to each columns and write the corresponding difference in another file along with some identification showing mismatched columns. Pointing out the mismatched columns is my main problem statement. For example we have files like:File 11|piyush|bangalore|dev1|piyush|bangalore|QA2|pankaj|bangalore|dev3|rohit|delhi|QAFile 21|piyush|bangalore|QA1|piyush|bangalore|QA2|pankaj|bangalore|dev3|rohit|bangalore|devThe expected output file looks somewhat like.File 11|piyush|bangalore|**dev**File 2 1|piyush|bangalore|**QA**File 13|rohit|**delhi**|**QA**File 23|rohit|**bangalore**|**dev**I want to achieve something like this where i can see the mismatched columns as well along with mismatched rows. I have tried diff File1 File2 > Diff_FileBut this is giving me only the mismatched records or rows. I am not getting any way to point out the mismatched columns as well. Please help me out if its possible to do is using shell script or awk command as i am very new to this. Thanks in advance.
Comparing two files and writing mismatched rows along with mismatched columns. Pointing out the mismatched columns is my main problem statement
shell script;text processing;awk;diff;file comparison
Python 3.x solution:diff_marked.py script:import sysfile1_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))Usage: (you may have another python version, the current case has been tested on python 3.5)python3.5 diff_marked.py File1 File2 > diff_outputdiff_output contents:File11|piyush|bangalore|**dev**File21|piyush|bangalore|**QA**File13|rohit|**delhi**|**QA**File23|rohit|**bangalore**|**dev**