Reputation: 11
I have two flat files. A.txt, B.txt
In A.txt, I have:
Name,reg no,address
A, 001, ABC, xyz, AA
B, 002, BBC, xxx, BB
In B.txt, I have:
Name,reg no,address
A, 001, ABC, xyz, AA
B, 002, BBC,xxx,BB
How can I compare these two files?
Upvotes: 1
Views: 90
Reputation: 43039
If you are interested in just comparing them and not bother about how they differ, you could use cmp
:
if ! cmp -s A.txt B.txt; then
echo "The files differ"
else
echo "The files are same"
fi
Upvotes: 1
Reputation: 1016
If the only difference between the two files is the commas, try passing each through "tr" to remove them:
cat A.txt | tr -d ',' > A.filtered.txt
Save each as a temporary file and then use 'diff' or more processing to make them similar. If the rows are out of order you can sort them before comparison.
Upvotes: 2