I have 2 files,
file1 ->
1 2 2 3 5 file2 ->
1 3 2 6 I want to the output to be stored in a 3rd file called file3 as
1,1,Match 2,2,Match 2,,NoMatch 3,3,Match 5,,NoMatch ,6,NoMatch I've tried,
sort file1 > file1sorted.txt sort file2 > file2sorted.txt # Combine the sorted files with a comma and store it in a new file paste -d ',' file1sorted.txt file2sorted.txt > mergedsortedfile.txt # Compare the columns and store the result in a new file awk -F',' '{print $1 == $2 ? "MATCH" : "NO MATCH"}' mergedsortedfile.txt > result.txt # Merge the result file with the already existing merged file paste -d ', ' mergedsortedfile.txt result.txt > final_result.txt The result appears like this,
1,1,MATCH 2,2,MATCH 2,3,NO MATCH 3,6,NO MATCH 5,,NO MATCH