2020年9月5日土曜日

ワンライナーでコマンド実行結果をdiffする


下記のようにすると、コマンドの実行結果を比較できます。

下記の例では、ファイルからコメント行を除外して diff してます。

ubuntu@MyComputer:~$ diff -y <(egrep -v '^#' /etc/hosts) <(egrep -v '^#' test.txt)
127.0.0.1       localhost                                     | 127.0.0.1       localhost
127.0.1.1       MyComputer.localdomain  MyComputer            <
127.0.0.1       webgoat.local                                 <
                                                              <
::1     ip6-localhost ip6-loopback                            <
fe00::0 ip6-localnet                                          <
ff00::0 ip6-mcastprefix                                       <
ff02::1 ip6-allnodes                                          <
ff02::2 ip6-allrouters                                        <