Hello I have 2 files with these words:
file: old.txt
toto
tata
tutu
file: new.txt
toto
tata
titi
tete
I would like to know the elements in more and less of these 2 lists.
in addition: titi, tete
less: tutu
The comm command does that
~/Temp$ comm -23 <(sort old.txt) <(sort new.txt)
tutu
~/Temp$ comm -13 <(sort old.txt) <(sort new.txt)
tete
titi
You can also print both results:
~/Temp$ comm -3 <(sort old.txt) <(sort new.txt)
tete
titi
tutu
Where option meaning is described in the comm man page :
- -1 suppress lines unique to FILE1
- -2 suppress lines unique to FILE2
- -3 suppress lines that appear in both files
Using grep:
$ grep -v -w -f old new
titi
tete
$ grep -v -w -f new old
tutu
titi, tete and tutu? What are you getting instead?
May 19, 2022 at 15:40
-w, Select only those lines containing matches that form whole words.). Added the switch to above solution. Thanks for the heads up, sir.
Jun 12, 2022 at 13:07
diff old.txt new.txt | sed -n 's/^</less:/p;s/^>/in addition:/p'
Use diff to show the differences and then use sed to reformat with "less:" and "in addition:"
Output:
less: tutu
in addition: titi
in addition: tete