Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #29703

Re: Reading a file from the back

From Eli the Bearded <*@eli.users.panix.com>
Newsgroups comp.os.linux.misc
Subject Re: Reading a file from the back
Date 2020-04-10 20:37 +0000
Organization Some absurd concept
Message-ID <eli$2004101637@qaz.wtf> (permalink)
References <r6hq2v$5bd$2@dont-email.me> <r6i5kr$q9o$2@dont-email.me> <slrnr91hqg.8ub.jj@iridium.wf32df>

Show all headers | View raw


In comp.os.linux.misc, Jim Jackson  <jj@franjam.org.uk> wrote:
> On 2020-04-07, Rich <rich@example.invalid> wrote:
>>> What is that command?
>> If by "from the end upwards" you really mean "backwards" (as in reverse 
>> byte order) then 'tac' is the command you are looking for.
> eerrrmmm... tac does reverse line (not byte) order!

I'm not aware of a standard tool that does 100% reverse byte order.
I've seen it as a programming challenge.

tac prints files line-by-line backwards.
rev reverses bytes line-by-line

`tac | rev` gets you a naive reversal, but the catch is, newlines are
not included.

In:
     ABCDEFG\n
     HIJKLMN\n

out of tac:
     HIJKLMN\n
     ABCDEFG\n

out of rev:
     GFEDCBA\n
     NMLKJIH\n

out of tac|rev:
     NMLKJIH\n
     GFEDCBA\n

out of a byte-by-byre reversal:
     \nNMLKJIH
     \nGFEDCBA

A simple byte-by-byte reverser:

     perl -ne '$all .= $_; END{ print scalar reverse $all }'

A more sophisticated tool would not rely on storing it all in
memory for every usage.

Elijah
------
optimized the perl for readibility, not speed or code golf

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Reading a file from the back Dieter Britz <dieterhansbritz@gmail.com> - 2020-04-07 12:01 +0000
  Re: Reading a file from the back Vasco Costa <vasco.costa@invalid.invalid> - 2020-04-07 12:12 +0000
  Re: Reading a file from the back Fenris <fenris@invalid.invalid> - 2020-04-07 12:12 +0000
  Re: Reading a file from the back Rich <rich@example.invalid> - 2020-04-07 15:18 +0000
    Re: Reading a file from the back Jim Jackson <jj@franjam.org.uk> - 2020-04-10 19:21 +0000
      Re: Reading a file from the back Eli the Bearded <*@eli.users.panix.com> - 2020-04-10 20:37 +0000
        Re: Reading a file from the back Eric Pozharski <whynot@pozharski.name> - 2020-04-11 15:22 +0300
          Re: Reading a file from the back Eli the Bearded <*@eli.users.panix.com> - 2020-04-13 01:03 +0000
            Re: Reading a file from the back Eric Pozharski <whynot@pozharski.name> - 2020-04-13 11:16 +0300
              Re: Reading a file from the back Eli the Bearded <*@eli.users.panix.com> - 2020-04-13 20:01 +0000
                Re: Reading a file from the back Eric Pozharski <whynot@pozharski.name> - 2020-04-14 12:14 +0300
                Re: Reading a file from the back Eli the Bearded <*@eli.users.panix.com> - 2020-04-14 16:50 +0000
      Re: Reading a file from the back Rich <rich@example.invalid> - 2020-04-10 21:40 +0000
  Re: Reading a file from the back The Natural Philosopher <tnp@invalid.invalid> - 2020-04-08 08:55 +0100

csiph-web