Read stdin and pass through pipeline to tee
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm playing around with xinput
to watch keyboard events.
I'd like to transform the output with awk
and pass it to tee
, printing to stdout and writing to a file simultaneously.
I watch events on device 14, type a single Space, then type Ctrl+C to exit:
$ xinput test 14
key release 36
key press 65
key release 65
key press 37
key press 54
^C
I can transform this with awk
:
$ xinput test 14 | awk ' print $NF '
36
65
65
37
54
^C
Or I can pipe it to tee
:
$ xinput test 14 | tee a.log
key release 36
key press 65
key release 65
key press 37
key press 54
^C
$ cat a.log
key release 36
key press 65
key release 65
key press 37
key press 54
But I can't pipe the transformed output to tee
:
$ xinput test 14 | awk ' print $NF ' | tee b.log
^C
$ cat b.log
I think I understand what's going on, and can boil it down to a simpler example where I cat
stdin to tr
and pipe that to tee
.
$ cat | tr a x | tee x.log
If I type A B Enter, then Ctrl+C, the pipeline aborts before printing to stdout or writing to x.log
(though the file itself is created):
ab
^C
$ cat x.log
If I type Ctrl+D instead of Ctrl+C, an EOF
character signals the end of input, and output gets printed to stdout and written to x.log
:
ab
xb
$ cat x.log
xb
I've tried a couple different approaches, but so far no success.
$ awk ' print $NF ' ; > >(tee x.log)
$ exec fd> >(tee x.log)
$ xinput test 14 | awk ' print $NF ' >& $fd
$ exec fd>&-
$ exec > >(tee x.log)
$ xinput test 14 | awk ' print $NF '
Can this be done?
shell pipe tee
add a comment |Â
up vote
1
down vote
favorite
I'm playing around with xinput
to watch keyboard events.
I'd like to transform the output with awk
and pass it to tee
, printing to stdout and writing to a file simultaneously.
I watch events on device 14, type a single Space, then type Ctrl+C to exit:
$ xinput test 14
key release 36
key press 65
key release 65
key press 37
key press 54
^C
I can transform this with awk
:
$ xinput test 14 | awk ' print $NF '
36
65
65
37
54
^C
Or I can pipe it to tee
:
$ xinput test 14 | tee a.log
key release 36
key press 65
key release 65
key press 37
key press 54
^C
$ cat a.log
key release 36
key press 65
key release 65
key press 37
key press 54
But I can't pipe the transformed output to tee
:
$ xinput test 14 | awk ' print $NF ' | tee b.log
^C
$ cat b.log
I think I understand what's going on, and can boil it down to a simpler example where I cat
stdin to tr
and pipe that to tee
.
$ cat | tr a x | tee x.log
If I type A B Enter, then Ctrl+C, the pipeline aborts before printing to stdout or writing to x.log
(though the file itself is created):
ab
^C
$ cat x.log
If I type Ctrl+D instead of Ctrl+C, an EOF
character signals the end of input, and output gets printed to stdout and written to x.log
:
ab
xb
$ cat x.log
xb
I've tried a couple different approaches, but so far no success.
$ awk ' print $NF ' ; > >(tee x.log)
$ exec fd> >(tee x.log)
$ xinput test 14 | awk ' print $NF ' >& $fd
$ exec fd>&-
$ exec > >(tee x.log)
$ xinput test 14 | awk ' print $NF '
Can this be done?
shell pipe tee
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm playing around with xinput
to watch keyboard events.
I'd like to transform the output with awk
and pass it to tee
, printing to stdout and writing to a file simultaneously.
I watch events on device 14, type a single Space, then type Ctrl+C to exit:
$ xinput test 14
key release 36
key press 65
key release 65
key press 37
key press 54
^C
I can transform this with awk
:
$ xinput test 14 | awk ' print $NF '
36
65
65
37
54
^C
Or I can pipe it to tee
:
$ xinput test 14 | tee a.log
key release 36
key press 65
key release 65
key press 37
key press 54
^C
$ cat a.log
key release 36
key press 65
key release 65
key press 37
key press 54
But I can't pipe the transformed output to tee
:
$ xinput test 14 | awk ' print $NF ' | tee b.log
^C
$ cat b.log
I think I understand what's going on, and can boil it down to a simpler example where I cat
stdin to tr
and pipe that to tee
.
$ cat | tr a x | tee x.log
If I type A B Enter, then Ctrl+C, the pipeline aborts before printing to stdout or writing to x.log
(though the file itself is created):
ab
^C
$ cat x.log
If I type Ctrl+D instead of Ctrl+C, an EOF
character signals the end of input, and output gets printed to stdout and written to x.log
:
ab
xb
$ cat x.log
xb
I've tried a couple different approaches, but so far no success.
$ awk ' print $NF ' ; > >(tee x.log)
$ exec fd> >(tee x.log)
$ xinput test 14 | awk ' print $NF ' >& $fd
$ exec fd>&-
$ exec > >(tee x.log)
$ xinput test 14 | awk ' print $NF '
Can this be done?
shell pipe tee
I'm playing around with xinput
to watch keyboard events.
I'd like to transform the output with awk
and pass it to tee
, printing to stdout and writing to a file simultaneously.
I watch events on device 14, type a single Space, then type Ctrl+C to exit:
$ xinput test 14
key release 36
key press 65
key release 65
key press 37
key press 54
^C
I can transform this with awk
:
$ xinput test 14 | awk ' print $NF '
36
65
65
37
54
^C
Or I can pipe it to tee
:
$ xinput test 14 | tee a.log
key release 36
key press 65
key release 65
key press 37
key press 54
^C
$ cat a.log
key release 36
key press 65
key release 65
key press 37
key press 54
But I can't pipe the transformed output to tee
:
$ xinput test 14 | awk ' print $NF ' | tee b.log
^C
$ cat b.log
I think I understand what's going on, and can boil it down to a simpler example where I cat
stdin to tr
and pipe that to tee
.
$ cat | tr a x | tee x.log
If I type A B Enter, then Ctrl+C, the pipeline aborts before printing to stdout or writing to x.log
(though the file itself is created):
ab
^C
$ cat x.log
If I type Ctrl+D instead of Ctrl+C, an EOF
character signals the end of input, and output gets printed to stdout and written to x.log
:
ab
xb
$ cat x.log
xb
I've tried a couple different approaches, but so far no success.
$ awk ' print $NF ' ; > >(tee x.log)
$ exec fd> >(tee x.log)
$ xinput test 14 | awk ' print $NF ' >& $fd
$ exec fd>&-
$ exec > >(tee x.log)
$ xinput test 14 | awk ' print $NF '
Can this be done?
shell pipe tee
asked Feb 18 at 0:45
ivan
650718
650718
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
I found two solutions.
Use
stdbuf
to runawk
with no output buffering.xinput test 14 | stdbuf -o0 awk ' print $NF ' | tee b.log
Add
system("")
call within theawk
scriptxinput test 14 | awk ' print $NF; system("") ' | tee b.log
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I found two solutions.
Use
stdbuf
to runawk
with no output buffering.xinput test 14 | stdbuf -o0 awk ' print $NF ' | tee b.log
Add
system("")
call within theawk
scriptxinput test 14 | awk ' print $NF; system("") ' | tee b.log
add a comment |Â
up vote
0
down vote
I found two solutions.
Use
stdbuf
to runawk
with no output buffering.xinput test 14 | stdbuf -o0 awk ' print $NF ' | tee b.log
Add
system("")
call within theawk
scriptxinput test 14 | awk ' print $NF; system("") ' | tee b.log
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I found two solutions.
Use
stdbuf
to runawk
with no output buffering.xinput test 14 | stdbuf -o0 awk ' print $NF ' | tee b.log
Add
system("")
call within theawk
scriptxinput test 14 | awk ' print $NF; system("") ' | tee b.log
I found two solutions.
Use
stdbuf
to runawk
with no output buffering.xinput test 14 | stdbuf -o0 awk ' print $NF ' | tee b.log
Add
system("")
call within theawk
scriptxinput test 14 | awk ' print $NF; system("") ' | tee b.log
edited Feb 18 at 2:26
answered Feb 18 at 1:10
ivan
650718
650718
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f424880%2fread-stdin-and-pass-through-pipeline-to-tee%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password