start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 28.9 ex Scripts Built by diff Chapter 28
Comparing Files
Next: 28.11 cmp and diff
 

28.10 Problems with diff and Tabstops

The diff (28.1) utility adds extra characters (>, <, +, and so on) to the beginning of lines. That can cause you real grief with tabstops because the extra characters diff adds can shift lines enough to make the indentation look wrong. The diff -t option expands TABs to 8-character tabstops and solves the problem.

If you use non-standard tabstops, though, piping diff's output through expand or pr -e (see article 41.4):

% diff afile bfile | expand -4

doesn't help because diff has already added the extra characters.

The best answers I've seen are the bash <() process substitution operator and the! (exclamation point) script . (9.18) You can expand TABs before diff sees them. For example, to show the differences between two files with 4-column tabstops:


bash$ diff <(expand -4 afile) <(expand -4 bfile)      bash

% diff `! expand -4 afile` `! expand -4 bfile`        other shells

- JP


Previous: 28.9 ex Scripts Built by diff UNIX Power ToolsNext: 28.11 cmp and diff
28.9 ex Scripts Built by diff Book Index28.11 cmp and diff

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System