Write another script that uses a command pipeline to take 2 files as parameters,
compare their contents and count how many lines are different. You will use
wc –l to count the differing lines.
I have tried everything I can think of to do this. I have tried cmp, comm, and diff. I am not looking for a complete solution, just a push in the right direction. What command would I use for this?
Have tried every combination of tags with these.
cmp file1 file2 | wc -l
Somehow I need to edit this to work right, not necessarily using the cmp command obviously.
I found that a side-by-side diff, suppressing context lines, is an effective method:
diff -y --suppress-common-lines file1 file2 | wc -l
This should do what you want
diff -U 0 file1 file2 | grep -c ^@
For example file1 contains
aaa bbb ccc
file2 contains
aaa ccc ddd
Result:
diff -U 0 file1 file2 | grep -c ^@
2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With