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

Unix Power ToolsUnix Power ToolsSearch this book

11.6. Problems with diff and Tabstops

The diff (Section 11.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 added by diff 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 nonstandard tabstops, though, piping diff's output through expand or pr -e doesn't help because diff has already added the extra characters.

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

$ diff <(expand -4 afile) <(expand -4 bfile)    process substitution
% diff `! expand -4 afile` `! expand -4 bfile`  other shells

Of course, nonstandard tabstops cause lots more problems than just with diff. If you can, you're better off using 8-space TABs and using spaces instead of tabs for indentation.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.