coreutils
[Top][All Lists]
Advanced

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

tac feature suggestion


From: braultbaron
Subject: tac feature suggestion
Date: Tue, 03 Jun 2014 19:13:02 +0200
User-agent: Webmail


Hello,


I have a feature suggestion for tac.
This would be an option:
 -c --bytes=N
where N would mean "ignore the last N bytes of the file".

In other words,
tac --bytes=<N> <file>
would produce the same output as:
head --bytes=-<N> <file> | tac
The fundamental difference is time and space efficiency.

In the second case, a copy of the file is made
in memory, which may be a problem if
the file is huge (e.g. a few gigabytes).
Instead, we could add this option
to allow tac to fseek accordingly
at the beginning of the process,
thus using only constant (i.e. BUFSIZ) memory,
and with no delay between tac invocation
and the beginning of the production of the output.

A slightly more complicated example:
tac --offset=1000000 <file> | head --bytes=1000
versus:
head --bytes=-k <file> | tac | head --bytes=1000

Assume the file takes 3 gigabytes.
In the first case, 1k bytes are read, and the output
is produced immediatly.
In the second case, 2G bytes are read and stored in memory,
and then, the output is produced.

The modifications in tac.c look rather straightforward.
If needed, I am willing to do it, even if
I am convinced this would take a few minutes
for an original author of the program.

Maybe a justification for this request would be welcome.
(if not, you can skip this)
I am currently programming a vim-like text editor
that operates on files that are too big to fit
in memory, and, for that project, I make
an intensive use of head, tail, tac and grep.
The basic idea is to rely on mature, simple
programs as much as possible.


Please forgive me if my english is not so clear,
I am no english native speaker.

Regards,
Johann Brault Baron





reply via email to

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