Subtracting one text string from another leaving unique characters, perhaps using awk

Is there any kind of means to subtract one column of information having message from an additional column having message and also get 3rd column having one-of-a-kind charcters, as an example making use of awk eg.

Input

ab   a
cd   d    
efg  ef

wanted result:

ab   a   b
cd   d   c
efg  ef  g
3
2022-06-07 14:41:24
Source Share
Answers: 2

Manatworks remedy is certainly penalty. This is simply a pure celebration choice.

while read line
do
  in=${line/ */}
  pat=${line/* /}
  echo $line ${in/$pat}
done < aba.dat

ab a b
cd d c
efg ef g
  • In in change (/) from $line what is an empty, adhered to by something - not in regex, yet globbing design
  • In pat it is the reverse: remove what is prior to the space. Getting rid of, due to the fact that the substitute component of $ src/pattern/replacement is empty
  • $ in/$ rub changes pat in in with absolutely nothing. The rub var requires to be noted as variable $ in comparison to the first variable/part (in)
1
2022-06-07 15:13:04
Source

Yes, awk is an ideal selection:

awk 'NF{t=$1;gsub("["$2"]","",t);print$0,t}' input

In instance the 2nd area might have personalities with unique definition in normal expression personality courses, those need to be run away. Addressing that in POSIX awk is extensive, so I upload the GNU awk choice just:

gawk 'NF{print$0,gensub("["gensub(/([\[\]^-])/,"\\\\\\1","g",$2)"]","","g",$1)}' input
5
2022-06-07 15:09:56
Source