3 added 7 characters in body
source | link

Using comm on the sorted data:

$  comm <( sort -n file1 ) <( sort -n file2 )
                1
                2
2
                3
5
        6

This output is tab-delimited. We can mark everything in columns 1 and 2 as "NoMatch" and in column 3 as "Match" with awk:

$ comm  <( sort -n file1 ) <( sort -n file2 ) |
  awk -F$'\t' 'BEGIN { OFS="," } $3 { print $3, $3, "Match"; next } { print $1, $2, "NoMatch" }'
1,1,Match
2,2,Match
2,,NoMatch
3,3,Match
5,,NoMatch
,6,NoMatch

The awk script will read tab-delimited input (-F$'\t') and use commas for the output field delimiter (OFS=","). If there's something in field 3, then it will output it twice with Match in the third field and continue with the next line. Otherwise, it will output fields 1 and 2 from the input together with NoMatch in the third field.

Using comm on the sorted data:

$  comm <( sort -n file1 ) <( sort -n file2 )
                1
                2
2
                3
5
        6

This output is tab-delimited. We can mark everything in columns 1 and 2 as "NoMatch" and in column 3 as "Match" with awk:

$ comm  <( sort -n file1 ) <( sort -n file2 ) |
  awk -F$'\t' 'BEGIN { OFS="," } $3 { print $3, $3, "Match"; next } { print $1, $2, "NoMatch" }'
1,1,Match
2,2,Match
2,,NoMatch
3,3,Match
5,,NoMatch
,6,NoMatch

The awk will read tab-delimited input (-F$'\t') and use commas for the output field delimiter (OFS=","). If there's something in field 3, then it will output it twice with Match in the third field and continue with the next line. Otherwise, it will output fields 1 and 2 from the input together with NoMatch in the third field.

Using comm on the sorted data:

$  comm <( sort -n file1 ) <( sort -n file2 )
                1
                2
2
                3
5
        6

This output is tab-delimited. We can mark everything in columns 1 and 2 as "NoMatch" and in column 3 as "Match" with awk:

$ comm  <( sort -n file1 ) <( sort -n file2 ) |
  awk -F$'\t' 'BEGIN { OFS="," } $3 { print $3, $3, "Match"; next } { print $1, $2, "NoMatch" }'
1,1,Match
2,2,Match
2,,NoMatch
3,3,Match
5,,NoMatch
,6,NoMatch

The awk script will read tab-delimited input (-F$'\t') and use commas for the output field delimiter (OFS=","). If there's something in field 3, then it will output it twice with Match in the third field and continue with the next line. Otherwise, it will output fields 1 and 2 from the input together with NoMatch in the third field.

    Post Undeleted by Kusalananda
2 added 948 characters in body
source | link

Using joincomm on the sorted filesdata:

$ join -o1.1,2.1comm -a1<( -a2sort -en '@'file1 -t,) file1<( sort -n file2 )
1,                1
                2,@
2,@
3,                3
@,2
5,@
@,        6

This join will output the fields of both files (-o1.1,2.1), along with each unpaired fields from both files (-a1 -a2)is tab-delimited. It will replace missing fields from either file with a @ (-e '@')We can mark everything in columns 1 and use a comma to separate the fields (-t,).

Running this through GNU2 as "NoMatch" and in column 3 as "Match" with sedawk:

$ joincomm -o1.1,2.1 -a1<( -a2sort -e '*'n file1 ) <( sort -n file2 ) | 
 sed '/@/s/$/awk -F$'\t' 'BEGIN { OFS=",NoMatch/;s/@//;t;s/$/" } $3 { print $3,Match/ $3, "Match"; next } { print $1, $2, "NoMatch" }'
 
1,1,Match
2,2,NoMatchMatch
2,,NoMatch
3,3,Match
,2,NoMatch
5,,NoMatch
,6,NoMatch

The sedawk will find a row containing a @read tab-delimited input (/@/-F$'\t') and append the string ,NoMatch touse commas for the end of that rowoutput field delimiter (s/$/OFS=",NoMatch/"). Then If there's something in field 3, then it will remove the @output it twice with (s/@//Match). If in the substitution actually happened (t), then it willthird field and continue with the next line. Otherwise, otherwise it will appendoutput fields 1 and 2 from the stringinput together with ,MatchNoMatch toin the line (s/$/,Match/)third field.

  

Using join on the sorted files:

$ join -o1.1,2.1 -a1 -a2 -e '@' -t, file1 file2
1,1
2,@
2,@
3,3
@,2
5,@
@,6

This join will output the fields of both files (-o1.1,2.1), along with each unpaired fields from both files (-a1 -a2). It will replace missing fields from either file with a @ (-e '@') and use a comma to separate the fields (-t,).

Running this through GNU sed:

$ join -o1.1,2.1 -a1 -a2 -e '*' file1 file2 | sed '/@/s/$/,NoMatch/;s/@//;t;s/$/,Match/'
 
1,1,Match
2,,NoMatch
2,,NoMatch
3,3,Match
,2,NoMatch
5,,NoMatch
,6,NoMatch

The sed will find a row containing a @ (/@/) and append the string ,NoMatch to the end of that row (s/$/,NoMatch/). Then it will remove the @ (s/@//). If the substitution actually happened (t), then it will continue with the next line, otherwise it will append the string ,Match to the line (s/$/,Match/).

 

Using comm on the sorted data:

$  comm <( sort -n file1 ) <( sort -n file2 )
                1
                2
2
                3
5
        6

This output is tab-delimited. We can mark everything in columns 1 and 2 as "NoMatch" and in column 3 as "Match" with awk:

$ comm  <( sort -n file1 ) <( sort -n file2 ) | 
  awk -F$'\t' 'BEGIN { OFS="," } $3 { print $3, $3, "Match"; next } { print $1, $2, "NoMatch" }'
1,1,Match
2,2,Match
2,,NoMatch
3,3,Match
5,,NoMatch
,6,NoMatch

The awk will read tab-delimited input (-F$'\t') and use commas for the output field delimiter (OFS=","). If there's something in field 3, then it will output it twice with Match in the third field and continue with the next line. Otherwise, it will output fields 1 and 2 from the input together with NoMatch in the third field.

 
    Post Deleted by Kusalananda
1
source | link

Using join on the sorted files:

$ join -o1.1,2.1 -a1 -a2 -e '@' -t, file1 file2
1,1
2,@
2,@
3,3
@,2
5,@
@,6

This join will output the fields of both files (-o1.1,2.1), along with each unpaired fields from both files (-a1 -a2). It will replace missing fields from either file with a @ (-e '@') and use a comma to separate the fields (-t,).

Running this through GNU sed:

$ join -o1.1,2.1 -a1 -a2 -e '*' file1 file2 | sed '/@/s/$/,NoMatch/;s/@//;t;s/$/,Match/'

1,1,Match
2,,NoMatch
2,,NoMatch
3,3,Match
,2,NoMatch
5,,NoMatch
,6,NoMatch

The sed will find a row containing a @ (/@/) and append the string ,NoMatch to the end of that row (s/$/,NoMatch/). Then it will remove the @ (s/@//). If the substitution actually happened (t), then it will continue with the next line, otherwise it will append the string ,Match to the line (s/$/,Match/).