GNU bug report logs - #12115
Please add tip about using tac to reverse a file byte-by-byte

Previous Next

Package: coreutils;

Reported by: Reuben Thomas <rrt <at> sc3d.org>

Date: Wed, 1 Aug 2012 21:46:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 12115 in the body.
You can then email your comments to 12115 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Wed, 01 Aug 2012 21:46:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Reuben Thomas <rrt <at> sc3d.org>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 01 Aug 2012 21:46:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: bug-coreutils <bug-coreutils <at> gnu.org>
Subject: Please add tip about using tac to reverse a file byte-by-byte
Date: Wed, 1 Aug 2012 22:37:42 +0100
Patch:

From 3c1b7d442dc6161e3c88703c9acc3f768f9ba689 Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt <at> sc3d.org>
Date: Wed, 1 Aug 2012 22:35:38 +0100
Subject: [PATCH] doc: Add tip on reversing a file byte-by-byte

* doc/coreutils.texi: Note how to use tac to reverse a file
byte-by-byte.
---
 doc/coreutils.texi |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 516ec73..66b0838 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -1625,6 +1625,12 @@ Use @var{separator} as the record separator,
instead of newline.

 @end table

+To reverse a file byte by byte, use:
+
+@example
+tac -r -s '.\| ' @var{file}
+@end example
+
 @exitstatus


-- 
1.7.9.5



-- 
http://rrt.sc3d.org




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Wed, 01 Aug 2012 21:58:02 GMT) Full text and rfc822 format available.

Message #8 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Reuben Thomas <rrt <at> sc3d.org>
Cc: 12115 <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Wed, 01 Aug 2012 15:50:18 -0600
[Message part 1 (text/plain, inline)]
On 08/01/2012 03:37 PM, Reuben Thomas wrote:
> Patch:
> 
>>From 3c1b7d442dc6161e3c88703c9acc3f768f9ba689 Mon Sep 17 00:00:00 2001
> From: Reuben Thomas <rrt <at> sc3d.org>
> Date: Wed, 1 Aug 2012 22:35:38 +0100
> Subject: [PATCH] doc: Add tip on reversing a file byte-by-byte
> 
> * doc/coreutils.texi: Note how to use tac to reverse a file
> byte-by-byte.
> ---
>  doc/coreutils.texi |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/doc/coreutils.texi b/doc/coreutils.texi
> index 516ec73..66b0838 100644
> --- a/doc/coreutils.texi
> +++ b/doc/coreutils.texi
> @@ -1625,6 +1625,12 @@ Use @var{separator} as the record separator,
> instead of newline.
> 
>  @end table
> 
> +To reverse a file byte by byte, use:
> +
> +@example
> +tac -r -s '.\| ' @var{file}

Cool tip.  But not quite accurate - you need a literal newline instead
of a space on the other side of that regex alternation.

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Wed, 01 Aug 2012 22:03:02 GMT) Full text and rfc822 format available.

Message #11 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: Eric Blake <eblake <at> redhat.com>
Cc: 12115 <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Wed, 1 Aug 2012 22:55:09 +0100
On 1 August 2012 22:50, Eric Blake <eblake <at> redhat.com> wrote:
>
> Cool tip.  But not quite accurate - you need a literal newline instead
> of a space on the other side of that regex alternation.

Sorry, I just copied what I found at

http://stackoverflow.com/questions/6438099/linux-command-line-tool-to-reverse-byte-order-change-endianess

without thinking. I see your point.

-- 
http://rrt.sc3d.org




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 07:31:02 GMT) Full text and rfc822 format available.

Message #14 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Reuben Thomas <rrt <at> sc3d.org>
Cc: 12115 <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 09:22:55 +0200
Reuben Thomas wrote:
...
> +To reverse a file byte by byte, use:
> +
> +@example
> +tac -r -s '.\| ' @var{file}
> +@end example
> +

Thanks!

That's a good demonstration.
Please note that it's not efficient and include the perl one-liner
for reference.

Here's a portable way to include the newline correction Eric mentioned:

nl='
'
tac -r -s ".\\|$nl" @var{file}

I would add that with a shell like bash or zsh you can do it more cleanly,
using $'\n' in place of the shell variable:
(note that below there's the added advantage of not having to
double-quote to include $nl and hence not having to double-backslash)

tac -r -s '.\|'$'\n' @var{file}




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 08:19:02 GMT) Full text and rfc822 format available.

Message #17 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Jim Meyering <jim <at> meyering.net>
Cc: 12115 <at> debbugs.gnu.org, Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 10:10:31 +0200
Jim Meyering <jim <at> meyering.net> writes:

> (note that below there's the added advantage of not having to
> double-quote to include $nl and hence not having to double-backslash)

You can have that with the variable as well.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 08:50:02 GMT) Full text and rfc822 format available.

Message #20 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 12115 <at> debbugs.gnu.org, Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 10:42:00 +0200
Andreas Schwab wrote:
> Jim Meyering <jim <at> meyering.net> writes:
>
>> (note that below there's the added advantage of not having to
>> double-quote to include $nl and hence not having to double-backslash)
>
> You can have that with the variable as well.

You're right.  We could write it like this:

    printf '\na\nb'|tac -rs '.\|'$nl

or even drop the quotes altogether:

    printf '\na\nb'|tac -rs .\\\|$nl

Golf is fun, but those seem less well suited as documentation examples.




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 09:39:01 GMT) Full text and rfc822 format available.

Message #23 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Jim Meyering <jim <at> meyering.net>
Cc: 12115 <at> debbugs.gnu.org, Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 11:31:21 +0200
Jim Meyering <jim <at> meyering.net> writes:

> Andreas Schwab wrote:
>> Jim Meyering <jim <at> meyering.net> writes:
>>
>>> (note that below there's the added advantage of not having to
>>> double-quote to include $nl and hence not having to double-backslash)
>>
>> You can have that with the variable as well.
>
> You're right.  We could write it like this:
>
>     printf '\na\nb'|tac -rs '.\|'$nl

No, you need the quotes around $nl.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 12:16:01 GMT) Full text and rfc822 format available.

Message #26 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 12115 <at> debbugs.gnu.org, Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 14:07:39 +0200
Andreas Schwab wrote:

> Jim Meyering <jim <at> meyering.net> writes:
>
>> Andreas Schwab wrote:
>>> Jim Meyering <jim <at> meyering.net> writes:
>>>
>>>> (note that below there's the added advantage of not having to
>>>> double-quote to include $nl and hence not having to double-backslash)
>>>
>>> You can have that with the variable as well.
>>
>> You're right.  We could write it like this:
>>
>>     printf '\na\nb'|tac -rs '.\|'$nl
>
> No, you need the quotes around $nl.

You need the double quotes around $nl with bash,
but not with zsh:

    zsh$ nl='
    quote> '
    zsh$ printf %s $nl

    zsh$




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 12:33:02 GMT) Full text and rfc822 format available.

Message #29 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: "Voelker, Bernhard" <bernhard.voelker <at> siemens-enterprise.com>
To: Jim Meyering <jim <at> meyering.net>, Andreas Schwab <schwab <at> linux-m68k.org>
Cc: "12115 <at> debbugs.gnu.org" <12115 <at> debbugs.gnu.org>,
	Reuben Thomas <rrt <at> sc3d.org>
Subject: RE: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 2 Aug 2012 12:25:02 +0000
Jim Meyering wrote (Thursday, August 02, 2012 2:08 PM):

> You need the double quotes around $nl with bash,
> but not with zsh:
> 
>     zsh$ nl='
>     quote> '
>     zsh$ printf %s $nl
> 
>    zsh$

For bash, one solution is:

	$ printf '\na\nb'|tac -rs '.\|'$(printf "\n")
	
	b
	a
	$

;-)

Have a nice day,
Berny








Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 13:27:03 GMT) Full text and rfc822 format available.

Message #32 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: "Voelker\, Bernhard" <bernhard.voelker <at> siemens-enterprise.com>
Cc: "12115 <at> debbugs.gnu.org" <12115 <at> debbugs.gnu.org>,
	Jim Meyering <jim <at> meyering.net>, Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 15:18:53 +0200
"Voelker, Bernhard" <bernhard.voelker <at> siemens-enterprise.com> writes:

> Jim Meyering wrote (Thursday, August 02, 2012 2:08 PM):
>
>> You need the double quotes around $nl with bash,

Or any other POSIX shell.

> For bash, one solution is:
>
> 	$ printf '\na\nb'|tac -rs '.\|'$(printf "\n")

No, command substitution strips trailing newlines.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 13:36:02 GMT) Full text and rfc822 format available.

Message #35 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: "12115 <at> debbugs.gnu.org" <12115 <at> debbugs.gnu.org>,
	Jim Meyering <jim <at> meyering.net>, "Voelker,
	Bernhard" <bernhard.voelker <at> siemens-enterprise.com>,
	Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 07:28:10 -0600
[Message part 1 (text/plain, inline)]
On 08/02/2012 07:18 AM, Andreas Schwab wrote:
>> For bash, one solution is:
>>
>> 	$ printf '\na\nb'|tac -rs '.\|'$(printf "\n")
> 
> No, command substitution strips trailing newlines.

So don't make it trailing:

printf '\na\nb'|tac -rs "$(printf '\n\\|.')"

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 14:09:01 GMT) Full text and rfc822 format available.

Message #38 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Eric Blake <eblake <at> redhat.com>
Cc: "12115 <at> debbugs.gnu.org" <12115 <at> debbugs.gnu.org>,
	Jim Meyering <jim <at> meyering.net>, "Voelker,
	Bernhard" <bernhard.voelker <at> siemens-enterprise.com>,
	Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 02 Aug 2012 16:00:43 +0200
Eric Blake <eblake <at> redhat.com> writes:

> On 08/02/2012 07:18 AM, Andreas Schwab wrote:
>>> For bash, one solution is:
>>>
>>> 	$ printf '\na\nb'|tac -rs '.\|'$(printf "\n")
>> 
>> No, command substitution strips trailing newlines.
>
> So don't make it trailing:
>
> printf '\na\nb'|tac -rs "$(printf '\n\\|.')"

It's still a useless command substitution.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Thu, 02 Aug 2012 14:12:02 GMT) Full text and rfc822 format available.

Message #41 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: Eric Blake <eblake <at> redhat.com>, Jim Meyering <jim <at> meyering.net>, "Voelker,
	Bernhard" <bernhard.voelker <at> siemens-enterprise.com>,
	"12115 <at> debbugs.gnu.org" <12115 <at> debbugs.gnu.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Thu, 2 Aug 2012 15:03:33 +0100
On 2 August 2012 15:00, Andreas Schwab <schwab <at> linux-m68k.org> wrote:
> Eric Blake <eblake <at> redhat.com> writes:
>
>> On 08/02/2012 07:18 AM, Andreas Schwab wrote:

[blah blah blah]

All this just because there's no standard interface in coreutils (or
indeed other GNU programs) to control the regexp engine, so you can
make "." match any character. LOL.

-- 
http://rrt.sc3d.org




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Fri, 01 Feb 2013 19:16:01 GMT) Full text and rfc822 format available.

Message #44 received at 12115 <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: Eric Blake <eblake <at> redhat.com>, Jim Meyering <jim <at> meyering.net>, "Voelker,
	Bernhard" <bernhard.voelker <at> siemens-enterprise.com>,
	"12115 <at> debbugs.gnu.org" <12115 <at> debbugs.gnu.org>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Fri, 1 Feb 2013 19:14:35 +0000
[Message part 1 (text/plain, inline)]
On 2 August 2012 15:03, Reuben Thomas <rrt <at> sc3d.org> wrote:

> On 2 August 2012 15:00, Andreas Schwab <schwab <at> linux-m68k.org> wrote:
> > Eric Blake <eblake <at> redhat.com> writes:
> >
> >> On 08/02/2012 07:18 AM, Andreas Schwab wrote:
>
> [blah blah blah]
>
> All this just because there's no standard interface in coreutils (or
> indeed other GNU programs) to control the regexp engine, so you can
> make "." match any character. LOL.
>
> --
> http://rrt.sc3d.org
>

Given how long it took how many experts to come up with a valid
incantation, it seems to me it *is* a useful documentation example. So can
we have an agreed version substituted into my patch and committed, please?

-- 
http://rrt.sc3d.org
[Message part 2 (text/html, inline)]

Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Fri, 01 Feb 2013 21:37:03 GMT) Full text and rfc822 format available.

Notification sent to Reuben Thomas <rrt <at> sc3d.org>:
bug acknowledged by developer. (Fri, 01 Feb 2013 21:37:03 GMT) Full text and rfc822 format available.

Message #49 received at 12115-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Reuben Thomas <rrt <at> sc3d.org>
Cc: 12115-done <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Fri, 01 Feb 2013 13:36:00 -0800
On 02/01/13 11:14, Reuben Thomas wrote:

> Given how long it took how many experts to come up with a valid
> incantation, it seems to me it *is* a useful documentation example.

Sure, but the valid incantation is a bit confusing, and it's not
documented correctly (it reverses characters, not bytes).
As far as I know there's no portable way to use 'tac' to
reverse a file byte-by-byte.

I installed this:


From dad0a3c743464664ed6a7ae8445cb58b8326db6d Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert <at> cs.ucla.edu>
Date: Fri, 1 Feb 2013 13:32:48 -0800
Subject: [PATCH] doc: say how to tac char-by-char

This fixes Bug#12115, reported by Reuben Thomas.
* doc/coreutils.texi (tac invocation): Document how to reverse a
file character by character.  Break out MS-DOS into a separate
section, like 'cat' does.
---
 doc/coreutils.texi | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index eac8d52..e29af8b 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -1613,10 +1613,7 @@ precedes in the file.
 @itemx --regex
 @opindex -r
 @opindex --regex
-Treat the separator string as a regular expression.  Users of @command{tac}
-on MS-DOS/MS-Windows should note that, since @command{tac} reads files in
-binary mode, each line of a text file might end with a CR/LF pair
-instead of the Unix-style LF.
+Treat the separator string as a regular expression.
 
 @item -s @var{separator}
 @itemx --separator=@var{separator}
@@ -1626,8 +1623,18 @@ Use @var{separator} as the record separator, instead of newline.
 
 @end table
 
+On systems like MS-DOS that distinguish between text and binary files,
+@command{tac} reads and writes in binary mode.
+
 @exitstatus
 
+Example:
+
+@example
+# Reverse a file character by character.
+tac -r -s 'x\|[^x]'
+@end example
+
 
 @node nl invocation
 @section @command{nl}: Number lines and write files
-- 
1.7.11.7






Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Fri, 01 Feb 2013 21:45:02 GMT) Full text and rfc822 format available.

Message #52 received at 12115-done <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 12115-done <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Fri, 1 Feb 2013 21:43:19 +0000
[Message part 1 (text/plain, inline)]
On 1 February 2013 21:36, Paul Eggert <eggert <at> cs.ucla.edu> wrote:

> On 02/01/13 11:14, Reuben Thomas wrote:
>
> > Given how long it took how many experts to come up with a valid
> > incantation, it seems to me it *is* a useful documentation example.
>
> Sure, but the valid incantation is a bit confusing, and it's not
> documented correctly (it reverses characters, not bytes).
> As far as I know there's no portable way to use 'tac' to
> reverse a file byte-by-byte.
>

Thanks!

What about a way to do it on a GNU system? It seems reasonable to document
GNU-specific hacks in GNU documentation when a portable solution is not
forthcoming.
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Fri, 01 Feb 2013 21:48:02 GMT) Full text and rfc822 format available.

Message #55 received at 12115-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Reuben Thomas <rrt <at> sc3d.org>
Cc: 12115-done <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Fri, 01 Feb 2013 13:46:38 -0800
On 02/01/13 13:43, Reuben Thomas wrote:
> What about a way to do it on a GNU system?

I think it works if you set LC_ALL='C', as the
C locale is unibyte on a GNU system, but someone
should double-check this.




Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Fri, 01 Feb 2013 21:53:01 GMT) Full text and rfc822 format available.

Message #58 received at 12115-done <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 12115-done <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Fri, 1 Feb 2013 21:52:04 +0000
[Message part 1 (text/plain, inline)]
On 1 February 2013 21:46, Paul Eggert <eggert <at> cs.ucla.edu> wrote:

> On 02/01/13 13:43, Reuben Thomas wrote:
> > What about a way to do it on a GNU system?
>
> I think it works if you set LC_ALL='C', as the
> C locale is unibyte on a GNU system, but someone
> should double-check this.
>

A bit of searching does not reveal to me how to verify or disprove this,
but how about using a known unibyte-locale such as an ISO8859 one? Or is
the problem then that there's none that can be guaranteed to exist?

-- 
http://rrt.sc3d.org
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Fri, 01 Feb 2013 22:06:01 GMT) Full text and rfc822 format available.

Message #61 received at 12115-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Reuben Thomas <rrt <at> sc3d.org>
Cc: 12115-done <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Fri, 01 Feb 2013 15:04:22 -0700
[Message part 1 (text/plain, inline)]
On 02/01/2013 02:43 PM, Reuben Thomas wrote:
> On 1 February 2013 21:36, Paul Eggert <eggert <at> cs.ucla.edu> wrote:
> 
>> On 02/01/13 11:14, Reuben Thomas wrote:
>>
>>> Given how long it took how many experts to come up with a valid
>>> incantation, it seems to me it *is* a useful documentation example.
>>
>> Sure, but the valid incantation is a bit confusing, and it's not
>> documented correctly (it reverses characters, not bytes).
>> As far as I know there's no portable way to use 'tac' to
>> reverse a file byte-by-byte.

Use LC_ALL=C to force single-byte characters.

>>
> 
> Thanks!
> 
> What about a way to do it on a GNU system? It seems reasonable to document
> GNU-specific hacks in GNU documentation when a portable solution is not
> forthcoming.

tac is a GNU program not standardized elsewhere, so if you have tac, it
is likely GNU tac to begin with.

The manual already contains:

@example
# Reverse a file character by character.
tac -r -s 'x\|[^x]'
@end example

Do we need a further example, or just modify that existing example to
call out the use of LC_ALL=C for reversing by bytes instead of characters?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#12115; Package coreutils. (Fri, 01 Feb 2013 22:25:02 GMT) Full text and rfc822 format available.

Message #64 received at 12115-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Reuben Thomas <rrt <at> sc3d.org>
Cc: 12115-done <at> debbugs.gnu.org
Subject: Re: bug#12115: Please add tip about using tac to reverse a file
	byte-by-byte
Date: Fri, 01 Feb 2013 14:23:25 -0800
On 02/01/13 13:52, Reuben Thomas wrote:
> how about using a known unibyte-locale such as an ISO8859 one? Or is
> the problem then that there's none that can be guaranteed to exist?

Yes, that's the problem.  POSIX does not require the existence
of any unibyte locale.  Even the C locale might be multibyte,
and is multibyte, at least on OS X systems.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 02 Mar 2013 12:24:02 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 114 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.