I have 2 text files to compare on their first column. The following comm command shows the common lines from the 2 files correctly.
comm develop1.txt qa1.txt -12
But the following diff command does not show the difference as expected.
diff develop1.txt qa1.txt --side-by-side
Expected output is as follows:
mysql-data/webservice 280292 | mysql-data/webservice 28684
But these two values are not on the same line because the number in the last column are different. I do actually need to compare the numbers in side-by-side format.
How can it be achieved?
If you’re up for something quick and dirty (not something I’d release into production but certainly okay for my own purposes):
The first line retrieves all the unique keys from both files into a list (won’t work if your keys have spaces but that’s likely to make any solution harder to implement, and it doesn’t appear to be the case here).
The second and third lines simply get the values for each key from the two files.
The
ifstatement then prints out the key and the two values but only where the values are different.Not pretty, not even thoroughly tested, but it may be adequate for your purposes. You do have to watch out for edge cases, like the possibility a key might exist multiple times in a file, or where the key may not be at the start of a line.