On Sat, 24 May 2008 11:09:00 +0200
Jim Meyering <[EMAIL PROTECTED]> wrote:
> > Suggested revision:
> >
> > -t, --field-separator=SEP
> > delimit keys with SEP, (instead of default whitespace)
>
> ...mentioning "whitespace" is misleading,
> since it implies ctype's isspace, while the standard requires that
> sort use a function like "isblank" to determine field boundaries.
> isspace can include far more than isblank. The latter is usually
> just SPACE and TAB, but sometimes (locale-dependent) several other
> characters.
How about:
-t, --field-separator=SEP
delimit keys with SEP, instead of default blanks.
In the 1970s blanks were space & tab, and still are in the
'C' locale. Today 'isblank(3)' automatically loads an
appropriate
"blanks" character set for locales such as Chinese, etc.
('Chinese' is a guess, I don't know if its "blanks" are different or
not. Replace with...?)
Also please consider including something like these bits (see notes below for a
rationale), the lack of which has sometimes lead me to needless trial & error:
The '-t' used to be a mnemonic, i.e: "tab character
separating fields is SEP".
The default blank is a character set, but SEP is only one
character.
Consecutive blanks count as one field.
HTH...
PS: for fans of minutiae, five examples from the "prior art", plus a
few notes.
The default field separator is white space and may be changed using the
-t option. Thus
sort -t: ...
sorts on fields separated by a :.
- The Unix System, S. R. Bourne, 1982
t_x_ 'Tab character' separating fields is 'x'. {...}
Under the -t_x_ option, fields are strings separated by _x_;
otherwise fields
are nonempty nonblank strings separated by blanks.
- Unix programmer's manual vol. 1, Bell Labs, 1983
t_x_ uses the character _x_ as field separator. A frequent field
separation character is the colon (:). Examples are found in
/etc/passwd ...
- An Intoduction to Berkeley Unix, P. Wang, 1988
-t_x_ (set tab character) When you use this option, replace the _x_
with the
character that is the field delimiter in the input file. This
character
replaces _SPACE_s, which become regular (nondelimiting)
characters.
- A Practical Guide to the Unix System 2nd Ed., M.
Sobell, 1989
-t_c_ Fields are separated with _c_ (default is any white space).
- Unix in a Nutshell, D. Gilly & O'Reilly & Associates,
1992
Notes on these quotes:
't' is, (or once was), a mnemonic for 'tab character'. In the 1970s
"tab" apparently must have had a flexible meaning, but in 2008 it's a
dead metaphor.
Bourne and Gilly call the default "white space", Bell Labs calls it
"nonempty nonblank strings separated by blanks" (maybe accurate, but
not friendly), and Sobell refers to _SPACE_ which his glossary defined
as "ASCII 32".
Surprisingly, nobody explicitly says that the default separator is a
character set, ASCII {8,32}, and '-t' replaces that with a single
char. I suppose a single char is a "set of one", but our '-t' SEP
can't have more than char as a member. (It'd be useful to have '-t'
accept sets.)
It's not made plain that consecutive separators count as one.
# given input:
# a:d
# c:b
# use ":" as separator. Sort by 2nd field.
% echo -e "a:d\nc:b" | sort -t: -k2,3
c:b
a:d
# add a redundant colon, repeat 2nd field sort.
% echo -e "a:d\nc::b" | sort -t: -k2,3
c::b
a:d
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]