coreutils
[Top][All Lists]
Advanced

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

Re: [head] wished an option to continue consuming the input after the sp


From: Thibault LE PAUL
Subject: Re: [head] wished an option to continue consuming the input after the specified number of lines has been read
Date: Tue, 16 Oct 2012 09:07:59 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120922 Icedove/10.0.7

Hello Bob.

I wasn't clear enough.
My goal was to do different things on the first lines and the last lines of same input, without using storage, thus using piped processes.
Then I used tee, to fork the pipe into two processes.
In my post before, I wanted to show three ways that work, including (head; cat) that does exactly the same as what would do head with the option I suggested in my initial post.
Opposite to that, my original way that fails :
rm /tmp/fifo1
mkfifo /tmp/fifo1
cat /tmp/fifo1|head -n2|sed 's/^/head &/' &
tee /tmp/fifo1|tail -n2|sed 's/^/tail &/'
That way, the /tmp/fifo1 fifo propagates SIGPIPE ahead to tee as soon as head has finished, then tee stops, and tail doesn't read the expected last lines, instead just the lines before tee aborts and EOF is read on pipe. The effect is observable on large input, like /usr/share/mysql/errmsg-utf8.txt
Also tried tee -i to ignore interrupts, but it is not the purpose of this option I suppose. No effect in our case.



Thibault Le Paul
Directeur Technique
address@hidden

10, Lotissement EL OMRANIA
Dely Brahim. Alger. Algérie
Tél: +213 (0) 21 91 74 11
Fax: +213 (0) 21 91 95 30
Mob: +213 (0) 555 052 487
Web: www.aebs-tech.com


On 16/10/2012 04:20, Bob Proulx wrote:
Hello Thibault,

Please keep the mailing list in the CC list so that everyone can
participate and learn from the discussion.  Thanks.

Thibault LE PAUL wrote:
The problem was with a tee.
Here is an example :

rm /tmp/fifo1
mkfifo /tmp/fifo1
cat /tmp/fifo1|(head -20;cat >/dev/null)|sed 's/^/head &/' &
#(cat /tmp/fifo1|sed -e '21,$d' -e 's/^/head &/') &
#(cat /tmp/fifo1|awk 'FNR<21{print "head "$0}')&
tee /tmp/fifo1|tail -20|sed 's/^/tail &/'

It works with cat, I didn't think to it.
You have shown part of what you are trying.  That is good.  But I
don't see a problem with what you are showing.  Please show us both
what you are expecting and also what you are seeing that you think is
a problem.

Using 'head -20' is problematic usage.  I recommend avoiding it.

I tried this:

  $ mkfifo fifo
  $ cat fifo | head -n1 | sed 's/^/head &/' &
  [1] 20056
  $ printf "foo\nfoo\nfoo\n" > fifo
  head foo
  $
  [1]+  Done                    cat fifo | head -n1 | sed 's/^/head &/'
  $

That all seems reasonable to me.  What problem are you seeing?

Bob

reply via email to

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