Skip to main content
deleted 31 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

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 am new to shell scripting and 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 

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 am new to shell scripting and 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 

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 
deleted 92 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

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 am new to shell scripting and 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 

Any help would be great. Please let me know if you need more information.

Thank you

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 am new to shell scripting and 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 

Any help would be great. Please let me know if you need more information.

Thank you

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 am new to shell scripting and 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 
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Source Link
Loading