11.9. More Friendly comm OutputSection 11.8 didn't show one of my least-favorite comm features. The default output (with text in "columns") confuses me if the lines of output have much text (especially text with spaces). For example, if I'm looking at two who (Section 2.8) listings to compare who was logged on at particular times, the columns in the who output are jumbled:
The commer script (see later) filters the comm output through sed. It converts comm's indentation characters (one TAB for lines in "column 2" and two TABs for lines in "column 3") into labels at the start of each output line. The default output looks like this: $ commer who1 who2 BOTH>root tty1 Oct 31 03:13 BOTH>jpeek tty2 Oct 31 03:15 TWO>jpeek pts/0 Oct 31 03:19 BOTH>jpeek pts/1 Oct 31 03:19 BOTH>jpeek pts/2 Oct 31 03:19 TWO>ally pts/4 Oct 31 03:19 BOTH>jpeek pts/3 Oct 31 03:19 ONE>xena pts/5 Nov 3 08:41 With the -i option, the script uses both labels and columns: $ commer -i who1 who2 BOTH> root tty1 Oct 31 03:13 BOTH> jpeek tty2 Oct 31 03:15 TWO>jpeek pts/0 Oct 31 03:19 BOTH> jpeek pts/1 Oct 31 03:19 BOTH> jpeek pts/2 Oct 31 03:19 TWO>ally pts/4 Oct 31 03:19 BOTH> jpeek pts/3 Oct 31 03:19 ONE> xena pts/5 Nov 3 08:41
Here's the script. The sed substitute (s) commands have one or two TABs between the first pair of slashes. Note that the sed script is inside double quotes ("), so the shell can substitute the value of $indent with an ampersand (&) into the sed script if the -i option was used:
NOTE: The commer script will be fooled by lines that already have TAB characters at the start. If this might be a problem, you can modify the script to search the files (grep "^TAB" >/dev/null) before starting comm. -- JP
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|