Paste command - question

Hi,

Below file content is output from pasting two files. Now, i want to output another file which just contains the difference on any line

For example:

JAY,2,,3,5,B+,JAY,2,,3,5,B+
ANN,5,,5,1,C,ANN,5,,5,2,C

Line JAY seems to have no difference. However, line ANN has difference in on column 5 (value 1 v/s value 2). So, line ANN should go in the new file.

Any help is appreciated.

TIA- jak

Maybe I didn't get it.
Please show the expected result.

Something like this should work:

paste -d '|'  file1 file2|awk -F \| ' $1 != $2 { print $1, $2; }' >newfile

It assumes the vertical bar (|) does not exist in either input file. You could also write the whole solution with awk rather than using two processes; it's not as "clean looking" but should be more efficient.

awk -v f1=file1 -v f2=file2 ' BEGIN {
    while( getline<f1 )
    {
        a=$0;
        getline<f2;
        if( a != $0 ) 
            printf( "%s %s\n", a, $0 );
    }
}' >newfile

hi ambious,

If you see line JAY (this line was originally in two separate file which i pasted into 1 line and 1 file using paste command). So, JAY has values 2,,3,5 and B+ in both the file. ANN has 5,,5,1 and C in one file and 5,,5,2 and C in 2nd file.

combined_file.txt

JAY,2,,3,5,B+,JAY,2,,3,5,B+
ANN,5,,5,1,C,ANN,5,,5,2,C

After two lines from two files are pasted in one file (as above), I want to separate line ANN (which has difference) into another file diff_file.txt

diff_file.txt should contain just ANN and not JAY

ANN,5,,5,1,C,ANN,5,,5,2,C

---------- Post updated at 10:31 PM ---------- Previous update was at 10:26 PM ----------

Thanks agama, i liked your solution of filtering right during the paste .. thanks

JaK