diffコマンドで横並びで差分を表示する方法
diffコマンドで横並びで差分を表示するには-yオプションを指定します。
オプションの説明
-y, --side-by-side output in two columns -W, --width=NUM output at most NUM (default 130) print columns --left-column output only the left column of common lines --suppress-common-lines do not output common lines
-yオプションを指定した場合
$ diff -y test1.txt test2.txt apple apple banana | grape orange orange lemon | mango peach <
-yオプションを指定しない場合
$ diff test1.txt test2.txt 2c2 < banana --- > grape 4,5c4 < lemon < peach --- > mango
-Wオプションで画面幅を設定できます(デフォルトは130)。
$ diff -y -W 60 test1.txt test2.txt apple apple banana | grape orange orange lemon | mango peach <
--left-columnオプションを指定すると共通行は左側にのみ表示されます。
$ diff -y -W 60 --left-column test1.txt test2.txt apple ( banana | grape orange ( lemon | mango peach <
--suppress-common-linesオプションを指定すると共通行を非表示にできます。
$ diff -y -W 60 --suppress-common-lines test1.txt test2.txt banana | grape lemon | mango peach <