P
P
popopa2018-09-19 22:46:36
bash
popopa, 2018-09-19 22:46:36

How to compare two variables (files) and show only differences?

Good day!
Tell me, please, how to compare 2 variables (you can file) and display only the differences?
var1="akker assault atl_diso atl_inspire atl_main_db atl_park atl_pl atl_prof atl_sale atl_shop atl_urban explod freemot groosha nordic pavi prof sport
"
differences:
( var3="atl_inspire groosha" )
if ; then
echo "not equal"
echo " $var3"
fi
How to get $var3?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2018-09-19
@gbg

diff a.txt b.txt

S
Saboteur, 2018-09-22
@saboteur_kiev

Try like this for $var1, $var2 variables
or like this for var1 and var2 files

diff --suppress-common-lines -a <(tr ' ' '\n'<var1) <(tr ' ' '\n'<var2) | grep -P -o "[<>]\s\K(.*)"|tr '\n' ' '

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question