bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multi-character tab


From: Bob Proulx
Subject: Re: multi-character tab
Date: Wed, 26 Oct 2005 10:09:04 -0600
User-agent: Mutt/1.5.9i

Alex van den Bogaerdt wrote:
> The documentation of sort has this to say:
>     To specify a zero byte (ASCII NUL (Null) character) as the field
>     separator, use the two-character string `\0', e.g., `sort -t '\0''.
> 
> Yet, this is what is produced:
>     $ sort -t '\0'
>     sort: multi-character tab `\0'
>     $

Hmm...  It works for me.

  printf "one\0two\nabc\0xyz\n" | sort -t "\0" -k2,2 | tr "\000" " "
  one two
  abc xyz
  printf "one\0two\nabc\0xyz\n" | sort -t "\0" -k1,1 | tr "\000" " "
  abc xyz
  one two

What version of sort are you using?  The first line of --version will
say this.

  sort --version

This may be a problem with the command shell trying to expand '\0'.
What shell are you using?  Can you try the bash shell since it is
known to work in this case?

What does echo show?

  echo sort -t "\0"
  sort -t \0

If you see something other than \0 then I suspect a shell issue.

> system: fedora core 3
> rpm: coreutils-5.2.1-31

Oh, I guess this does imply the version of sort almost answering my
question above.  But please double check anyway in case some other
sort is becoming involved unexpectedly.  This is working fine for me
on my Debian GNU/Linux machine using both 5.2.1 and current CVS with
bash 3.0 as my shell.

> In addition, I'd be very much obliged if you can reply to me and tell
> me how I can specify a tab character as field separator without having
> to resort to actually putting a tab char in my script. -t '\t' doesn't
> do it I'm afraid, nor does -t '[\t]' .

Yes, a common topic of discussion.  Here are the two common ways of
creating ascii tabs on the comand line.  The first is maximally
portable back to very old systems and are preferred by some due the
good level of portability.  The second is yet another way.  The third
way is my preferred method on modern systems because I think it is the
clearest and most direct method.

  TAB=`awk 'BEGIN{printf "\t";}'`
  TAB=`echo | tr "\012" "\011"`
  TAB=$(printf "\t")

In all cases the scheme creates the tab first and then uses it in the
sort with a variable such as "sort -t $TAB".

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]