Re: tab as sort's field-separator
[email protected] (Bob Proulx)
| Newsgroups | gmane.comp.gnu.textutils.bugs |
|---|---|
| Message-ID | <[email protected]> |
> Clearly the workaround not working with tcsh is a shell problem. But > I don't see how not being able to specify a literal for a tab as an > option to sort is a shell problem. I believe it is a shell problem as well. > Did you see the two examples of using tab with sort at the very end > of my original message (and below) after my signature? The error is > independent of the shell used. Then both shells are causing you the trouble. But the problem as we shall see is with your quoting. > >RH 7.2, textutils-2.0.14-2 > > > >$ sort -t'\t' -u -k2,2 -k1,1 /tmp/x > >sort: multi-character tab `\t' Try using 'echo' to see what the sort command is seeing. This is what I get on linux using different versions of bash. bash-2.04: echo sort -t'\t' -u -k2,2 -k1,1 /tmp/x sort -t -u -k2,2 -k1,1 /tmp/x bash-2.05: echo sort -t'\t' -u -k2,2 -k1,1 /tmp/x sort -t\t -u -k2,2 -k1,1 /tmp/x See that literal '\t' there as two characters in the bash-2.05 example? Sort is complaining that only one character is allowed as an option. It is seeing two. It is seeing a 'backslash' followed by a 't'. You need to make it see only one character. Which you appear to be aware of because you posted a workaround. > >I can work around this in bash using: > > TAB=`echo -e "\t"` > > sort -t"$TAB" ... You seem to see that this is just an issue with your shell quoting. You can see that \t is espanded inside of "" but not in ''. So you are using "\t" in the echo to expand to be a tab. But then later you are trying to use '\t' which works with some shells and apparently not in the newer bash. This seems to be different in different versions of bash. I don't see this problem when using the hpux /bin/sh posix shell, for example. If someone knows what the standards say about quoting and backslash expansion I would be interested in hearing about it. Likely this is a change required by the Austin group or some such. I will give them the benefit of the doubt until someone says otherwise. > $ strings /bin/sort | grep multi > ... > multi-character tab `%s' That is the error message code in sort which is triggered when the -t option has more than one character. We are in agreement there, right? > Thanks for the pointer to the improved textutils. I'll need to wait > for them to be in the released baseline since I'll be distributing the > script I'm working on. Any idea when that will be? The alexautils are a code fork off of the GNU tools. They implement their own set of features and options. As far as I know there are no plans to merge those into the main GNU source. Friendly competition is a good thing and working examples of alternative implementations are always welcome. Meanwhile, try this: sort -t"\t" -u -k2,2 -k1,1 /tmp/x As a "\t" I believe the shell will expand the tab. As in your posted workaround. Bob