liberte@uiucdcs.UUCP (06/02/84)
#N:uiucdcs:8200022:000:1865 uiucdcs!liberte Jun 1 20:11:00 1984 Subject: Sort does not ignore blanks given no tabchar. Index: /usr/src/usr.bin/sort.c 4.2 bsd Description: The behavior of sort is wrong if no tabchar is specified (-t option) and the number of blanks between fields varies. It does not ignore blanks as the manual would lead one to believe it should: "Under the -tx option, fields are strings separated by x; otherwise fields are nonempty nonblank strings separated by blanks." The 4.1 version had a different, though related bug in which the -b option had no effect if the -t option was used. Even now, the -b option is not so useful with the -t option. Nevertheless, there is an ambiguity in the manual regarding the -b option. The way `sort` works, ignoring blanks for -pos2 (the termination position) means include the blanks in the field comparison. The trick of my fix is to stop before those blanks if no tabchar is given. Repeat-By: sort +0 -1 <<input this is a test this is too this is also input will sort the last two lines after the first since the spaces after "this" make them greater. The sort should be inverse order. Fix: This fix will work for 4.1 versions, too, in which the "||" was "&&" instead, which had the effect of not ignoring blanks before the first position unless specifically indicated with -b. *** is the original *** /tmp/,RCSt1016941 Fri Jun 1 19:13:41 1984 --- sort.c Fri Jun 1 17:58:01 1984 *************** *** 720,726 else goto ret; } } ! if(tabchar==0||fp->bflg[j]) while(blank(*p)) p++; i = fp->n[j]; --- 724,730 ----- else goto ret; } } ! if((!j && tabchar==0)||fp->bflg[j]) /* j is the pos #, 0 or 1 */ while(blank(*p)) p++; i = fp->n[j]; Daniel LaLiberte (ihnp4!uiucdcs!liberte) U of Illinois, Urbana-Champaign, Computer Science {moderation in all things - including moderation}