[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Not a bug, a wish
From: |
Martin Bernreuther |
Subject: |
Re: Not a bug, a wish |
Date: |
Thu, 27 Mar 2008 01:26:23 +0100 |
User-agent: |
KMail/1.9.9 |
Hello,
Am Mittwoch, 26. März 2008 schrieb Micah Cowan:
> > I thank you very much for devolopping coreutils that allows quick and
> > simple replacement of SQL queries and check. What I would appreciate is
> > a tool that does head and tail in one command, giving the top and bottom
> > lines from a piped output.
I also think that such a command would be easier to use than head and tail,
which both just extract lines from a stream and therefore do a similar thing.
> Do you literally mean just the one top line and one bottom line? That
> could easily be achieved with the sed command: sed -n '1p;$p'.
Nice.
In my case I often want to extract some part of a file (or stream).
Consider something like
headtail 3:5 inputfile
and
head -n 5 inputfile | tail -n $[5-3+1]
The first version would be "easier to understand" and might
be more efficient to implement.
(I found the pipe mechanism for file sizes >100 GB not very reliable.)
Often you like to remove a header...
A negative number is sometimes used in scripting-languages
to mark or count from the end of the file like
headtail 2:-1 inputfile
To just remove the first line a combination of tail and wc
theoretically would work (quite inefficient)
tail -n $[`wc -l <inputfile`-1] inputfile
You might also want to remove a footer like
headtail 2:-2 inputfile
Using head and tail: How does that work (with n header lines and m footer
lines)?
Is there another easy way to do it? Is "sed" the command the way to go?
> If you need more lines, sed can still do it, but requires a bit more
> work. You might look to a simple solution in
> awk/Perl/your-scripting-language-of-choice.
No!!! I definitely don't want to use Perl or "my-scripting-language-of-choice"
for such an easy task. What is the sense of these tools then?
You probably master most of the coreutil-tasks also with these
scripting-languages-of-choice, don't you?
Martin Bernreuther
--
_________________________________________
Martin Bernreuther address@hidden