redirection, paste and tee?
redirection, paste and tee?
am 06.01.2008 19:48:09 von tmp123
Hello,
First of all, thanks for your help.
After a few hours reading post about redirections, exec, ... I can not
find a final solution to this problem:
Given to programs, "foo" and "bar", the objective is a command who
appends to the result of "foo" the result of "foo | cut -f 4 | bar".
Append in the same way than "paste" does.
That means:
+--> cut --> bar --+
foo -->| +->paste
+-----------------------+
Of course, without temporals ;-)
Probably, I need tee to split the output of "foo" to two streams, but,
how?
Thanks a lot.
Re: redirection, paste and tee?
am 06.01.2008 19:59:31 von tmp123
On Jan 6, 7:48=A0pm, tmp123 wrote:
> Hello,
>
> First of all, thanks for your help.
>
> After a few hours reading post about redirections, exec, ... I can not
> find a final solution to this problem:
>
> Given to programs, "foo" and "bar", the objective is a command who
> appends to the result of "foo" the result of "foo | cut -f 4 | bar".
> Append in the same way than "paste" does.
>
> That means:
>
> =A0 =A0 =A0 =A0 =A0+--> cut --> bar --+
> foo -->| =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0+->paste
> =A0 =A0 =A0 =A0 =A0+-----------------------+
>
> Of course, without temporals ;-)
>
> Probably, I need tee to split the output of "foo" to two streams, but,
> how?
>
> Thanks a lot.
Sorry, I've forgot an small clarification:
The following command produces the expected result:
mkfifo pp
foo | tee pp | cut -f 3 | bar | paste - pp
But an external fifo is need.
Thanks again.
Re: redirection, paste and tee?
am 06.01.2008 20:59:24 von Cyrus Kriticos
tmp123 wrote:
> On Jan 6, 7:48 pm, tmp123 wrote:
>>
>> First of all, thanks for your help.
>>
>> After a few hours reading post about redirections, exec, ... I can not
>> find a final solution to this problem:
>>
>> Given to programs, "foo" and "bar", the objective is a command who
>> appends to the result of "foo" the result of "foo | cut -f 4 | bar".
>> Append in the same way than "paste" does.
>>
>> That means:
>>
>> +--> cut --> bar --+
>> foo -->| +->paste
>> +-----------------------+
>>
>> Of course, without temporals ;-)
>>
>> Probably, I need tee to split the output of "foo" to two streams, but,
>> how?
>>
>> Thanks a lot.
>
> Sorry, I've forgot an small clarification:
>
> The following command produces the expected result:
>
> mkfifo pp
> foo | tee pp | cut -f 3 | bar | paste - pp
[GNU bash]
FOO="$(foo)"
echo "$FOO" | cut -f 3- | bar| paste - <(echo "$FOO")
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: redirection, paste and tee?
am 07.01.2008 12:13:12 von tmp123
On Jan 6, 8:59 pm, Cyrus Kriticos
wrote:
> tmp123 wrote:
> > On Jan 6, 7:48 pm, tmp123 wrote:
>
> >> First of all, thanks for your help.
>
> >> After a few hours reading post about redirections, exec, ... I can not
> >> find a final solution to this problem:
>
> >> Given to programs, "foo" and "bar", the objective is a command who
> >> appends to the result of "foo" the result of "foo | cut -f 4 | bar".
> >> Append in the same way than "paste" does.
>
> >> That means:
>
> >> +--> cut --> bar --+
> >> foo -->| +->paste
> >> +-----------------------+
>
> >> Of course, without temporals ;-)
>
> >> Probably, I need tee to split the output of "foo" to two streams, but,
> >> how?
>
> >> Thanks a lot.
>
> > Sorry, I've forgot an small clarification:
>
> > The following command produces the expected result:
>
> > mkfifo pp
> > foo | tee pp | cut -f 3 | bar | paste - pp
>
> [GNU bash]
>
> FOO="$(foo)"
> echo "$FOO" | cut -f 3- | bar| paste - <(echo "$FOO")
>
Hello,
Thanks a lot for your answer.
"foo" is a never ending process. Is the solution valid with this
restriction?
Kind regards.
Re: redirection, paste and tee?
am 07.01.2008 12:24:16 von Cyrus Kriticos
tmp123 wrote:
> On Jan 6, 8:59 pm, Cyrus Kriticos
> wrote:
>> tmp123 wrote:
>>> On Jan 6, 7:48 pm, tmp123 wrote:
>>>> First of all, thanks for your help.
>>>> After a few hours reading post about redirections, exec, ... I can not
>>>> find a final solution to this problem:
>>>> Given to programs, "foo" and "bar", the objective is a command who
>>>> appends to the result of "foo" the result of "foo | cut -f 4 | bar".
>>>> Append in the same way than "paste" does.
>>>> That means:
>>>> +--> cut --> bar --+
>>>> foo -->| +->paste
>>>> +-----------------------+
>>>> Of course, without temporals ;-)
>>>> Probably, I need tee to split the output of "foo" to two streams, but,
>>>> how?
>>>> Thanks a lot.
>>> Sorry, I've forgot an small clarification:
>>> The following command produces the expected result:
>>> mkfifo pp
>>> foo | tee pp | cut -f 3 | bar | paste - pp
>> [GNU bash]
>>
>> FOO="$(foo)"
>> echo "$FOO" | cut -f 3- | bar| paste - <(echo "$FOO")
>>
>
> Hello,
>
> Thanks a lot for your answer.
>
> "foo" is a never ending process. Is the solution valid with this
> restriction?
No.
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: redirection, paste and tee?
am 07.01.2008 15:11:18 von Stephane CHAZELAS
On Sun, 6 Jan 2008 10:59:31 -0800 (PST), tmp123 wrote:
[...]
>> +--> cut --> bar --+
>> foo -->| +->paste
>> +-----------------------+
>>
>> Of course, without temporals ;-)
>>
>> Probably, I need tee to split the output of "foo" to two streams, but,
>> how?
>>
>> Thanks a lot.
>
> Sorry, I've forgot an small clarification:
>
> The following command produces the expected result:
>
> mkfifo pp
> foo | tee pp | cut -f 3 | bar | paste - pp
>
> But an external fifo is need.
[...]
You can't without a named pipe with usual Unix shells.
You can probably do it in perl on systems with /dev/fd/
though.
$^F = 0xffff;
pipe AR, AW;
pipe BR, BW;
if (fork() == 0) {
open STDOUT, ">&AW";
close AR; close BR; close AW;
exec "foo | tee /dev/fd/" . fileno BW;
}
open STDIN, "<&AR";
close AR; close AW; close BW;
exec "cut -f 3 | bar | paste - /dev/fd/" . fileno BR;
--
Stephane