# 元データの確認(以下、他の実行例でも共通)
$ ls -l a.txt b.txt
-rw-r--r-- 1 ycos users 37 Oct 6 21:46 a.txt
-rw-r--r-- 1 ycos users 25 Oct 6 21:48 b.txt
$ cat a.txt
This is File A
same DATA
End of file
$ cat b.txt
This is File B
same DATA
# ファイルの比較
$ diff a.txt b.txt
1c1
< This is File A
---
> This is File B
3d2
< End of file
# ファイルの比較(冗長な表示)
$ diff -c a.txt b.txt
*** a.txt Sat Oct 6 21:46:58 2007
--- b.txt Sat Oct 6 21:48:39 2007
***************
*** 1,3 ****
! This is File A # ! は変更箇所
same DATA
- End of file # - はb.txt に含まれない行
--- 1,2 ----
! This is File B
same DATA
# a.txt を b.txt と同じ内容にするための edコマンドスクリプトの生成
# このスクリプトは最終的に上書きをしない内容であるため、
# 必要であれば更新、表示するためのコマンドを追加する必要がある
$ diff -e a.txt b.txt
3d
1c
This is File B
.
# ed 用スクリプトの生成、印刷コマンドを追加
$ diff -e a.txt b.txt > c.ed
(最後にコマンドを追加 1,$p)
$ cat c.ed
3d
1c
This is File B
.
1,$p # 手で追加した行。ファイル内容を表示
$ ed a.txt < c.ed
37
This is File B
same DATA
?