0

Consider two files like below:


$ cat f1.txt
col_name        data_type       comment
name                    string
age                     int
income                  int
access_count1           int

$ cat f2.txt
col_name        data_type       comment
name                    string
city                    string
income                  int
edr                     time
access_count1           int
bcwer                   int

I need to compare the two files (not line by line), since any row can have new values, and show:

  1. New values in f2.txt
  2. Any updated values in f1.txt

I have tried:


$ diff -y --suppress-common-lines f1.txt f2.txt
age                     int                                   | city                    string
                                                              > edr                     time
                                                              | bcwer                   int

It's not in a readable format.

1
  • It is intended to be readable. Maybe pipe it through expand -t 4, as the excess width is probably due to tabs. Lines marked | are changed lines, showing file 1 to the left and file 2 to the right. Lines marked < or > show lines only present in one file (inserts or deletes). It becomes natural to read quite quickly. Showing changes in the general case (e.g. "This paragraph of 11 lines was moved down by three paragraphs, and these eight words had typos fixed") quickly becomes too complex. Can you clarify what you would like to see? I'm working on a "blink" viewer, but it is not easy. May 25, 2022 at 16:08

1 Answer 1

0

If you drop the -y option in your diff statement, you should get:

3c3
< age                     int
---
> city                    string
4a5
> edr                     time
5a7
> bcwer                   int

If you don't want all the extraneous info, you can grep it and get a nice, clean result like this:

$ diff --suppress-common-lines f1.txt f2.txt | grep -e "^[<>]"
< age                     int
> city                    string
> edr                     time
> bcwer                   int

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .