bug-coreutils
[Top][All Lists]
Advanced

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

bug#8081: sort -z and shuf -z don't work


From: Harald Dunkel
Subject: bug#8081: sort -z and shuf -z don't work
Date: Sat, 19 Feb 2011 08:24:45 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101210 Thunderbird/3.1.7

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Package: coreutils
Version: 8.10


Hi folks,

According to the man page "sort -z" and "shuf -z" are supposed to
"end lines with 0 byte, not newline". This doesn't work. Example:

% ( echo 1; echo 2; echo 3 ) | tac | sort -z | xargs -0 -L 1 echo xxx
xxx 3
2
1

There are 3 line on input, so there should be 3 lines with "xxx" on
output. If I omit the -z, then it works:

% ( echo 1; echo 2; echo 3 ) | tac | sort | xargs -L 1 echo xxx
xxx 1
xxx 2
xxx 3

Please note that sort's input stream is not zero-terminated. "tac"
doesn't support this option. sort(1) doesn't mention such an
assumption, either. Obviously there are many more tools with
this restriction.

Instead of mixing input and output options I would suggest to
introduce 2 new tools "nl2zero" and "zero2nl". Sample implementation:

% alias nl2zero='tr \\n \\0'
% alias zero2nl='tr \\0 \\n'
% ( echo 1; echo 2; echo 3 ) | tac | nl2zero | sort -z | xargs -0 -L 1 echo xxx
xxx 1
xxx 2
xxx 3


Regards

Harri
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1fcD0ACgkQUTlbRTxpHjd/6wCfTWOs/o3AYk2205IRJU0b5hjj
PyMAnRChOFwIdsKps9wyJwjGs7Cwd7ba
=Kab0
-----END PGP SIGNATURE-----





reply via email to

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