Unixでの2つのファイルの比較

Unixでの2つのファイルの比較

次の2つのファイルを考えてみましょう。


$ 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

すべての行に新しい値がある可能性があるため、2つのファイルを1行ずつ比較せずに比較する必要があり、次のように表示する必要があります。

  1. f2.txtの新しい値
  2. f1.txtの更新値

私は試した:


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

読める形式ではありません。

ベストアンサー1

-y宣言からオプションを削除すると、diff次のようになります。

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

不要な情報をすべて望まない場合は、grep次のような素晴らしい、きれいな結果を得ることができます。

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

おすすめ記事