AWK in the middle of a pipe returns no output
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I want to process all changed logfiles from apache and made a simple oneliner:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print '
This is exactly my start. But if I pipe that output further, I get no output:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | wc -l
Anyway, if I use 'ls', 'tail' (what I really want), there is never output
(in another console, running the first statement, I know, there are changes).
I tried with adding stdbuf, fflush(), nothing works. I dont understand the problem!
I want to keep this onliner into a script, which I can use as a string point. Otherwise, I could (but dont wish to) use xargs.
Any help or tips would be fine!
awk pipe
add a comment |Â
up vote
0
down vote
favorite
I want to process all changed logfiles from apache and made a simple oneliner:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print '
This is exactly my start. But if I pipe that output further, I get no output:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | wc -l
Anyway, if I use 'ls', 'tail' (what I really want), there is never output
(in another console, running the first statement, I know, there are changes).
I tried with adding stdbuf, fflush(), nothing works. I dont understand the problem!
I want to keep this onliner into a script, which I can use as a string point. Otherwise, I could (but dont wish to) use xargs.
Any help or tips would be fine!
awk pipe
So it still doesn't work with the correct quoting in place?
â Jesse_b
Jul 18 at 22:14
1
turn off buffering (or at least make it line-based) for all the things. unix.stackexchange.com/questions/25372/â¦
â thrig
Jul 18 at 22:25
Thanks for all hints! It just needs to much time to solve this problem - I am working for hours on that. After applying all recommendations to disable buffering (some of them I tried also bevore) and none worked, I am going back to use xargs. It is even an unsupported debian (squeeze - a new hardware is on my table sinde two years ...). Thanks anyone.
â mabra
Jul 18 at 23:26
1
I answered the question, but it's really not clear what your desired result is. Theawk
command here does nothing at all.wc
andtail
don't print anything until all data is read.ls
doesn't read stdin at all.
â jordanm
Jul 19 at 1:35
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to process all changed logfiles from apache and made a simple oneliner:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print '
This is exactly my start. But if I pipe that output further, I get no output:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | wc -l
Anyway, if I use 'ls', 'tail' (what I really want), there is never output
(in another console, running the first statement, I know, there are changes).
I tried with adding stdbuf, fflush(), nothing works. I dont understand the problem!
I want to keep this onliner into a script, which I can use as a string point. Otherwise, I could (but dont wish to) use xargs.
Any help or tips would be fine!
awk pipe
I want to process all changed logfiles from apache and made a simple oneliner:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print '
This is exactly my start. But if I pipe that output further, I get no output:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | wc -l
Anyway, if I use 'ls', 'tail' (what I really want), there is never output
(in another console, running the first statement, I know, there are changes).
I tried with adding stdbuf, fflush(), nothing works. I dont understand the problem!
I want to keep this onliner into a script, which I can use as a string point. Otherwise, I could (but dont wish to) use xargs.
Any help or tips would be fine!
awk pipe
edited Jul 18 at 22:14
asked Jul 18 at 22:08
mabra
215
215
So it still doesn't work with the correct quoting in place?
â Jesse_b
Jul 18 at 22:14
1
turn off buffering (or at least make it line-based) for all the things. unix.stackexchange.com/questions/25372/â¦
â thrig
Jul 18 at 22:25
Thanks for all hints! It just needs to much time to solve this problem - I am working for hours on that. After applying all recommendations to disable buffering (some of them I tried also bevore) and none worked, I am going back to use xargs. It is even an unsupported debian (squeeze - a new hardware is on my table sinde two years ...). Thanks anyone.
â mabra
Jul 18 at 23:26
1
I answered the question, but it's really not clear what your desired result is. Theawk
command here does nothing at all.wc
andtail
don't print anything until all data is read.ls
doesn't read stdin at all.
â jordanm
Jul 19 at 1:35
add a comment |Â
So it still doesn't work with the correct quoting in place?
â Jesse_b
Jul 18 at 22:14
1
turn off buffering (or at least make it line-based) for all the things. unix.stackexchange.com/questions/25372/â¦
â thrig
Jul 18 at 22:25
Thanks for all hints! It just needs to much time to solve this problem - I am working for hours on that. After applying all recommendations to disable buffering (some of them I tried also bevore) and none worked, I am going back to use xargs. It is even an unsupported debian (squeeze - a new hardware is on my table sinde two years ...). Thanks anyone.
â mabra
Jul 18 at 23:26
1
I answered the question, but it's really not clear what your desired result is. Theawk
command here does nothing at all.wc
andtail
don't print anything until all data is read.ls
doesn't read stdin at all.
â jordanm
Jul 19 at 1:35
So it still doesn't work with the correct quoting in place?
â Jesse_b
Jul 18 at 22:14
So it still doesn't work with the correct quoting in place?
â Jesse_b
Jul 18 at 22:14
1
1
turn off buffering (or at least make it line-based) for all the things. unix.stackexchange.com/questions/25372/â¦
â thrig
Jul 18 at 22:25
turn off buffering (or at least make it line-based) for all the things. unix.stackexchange.com/questions/25372/â¦
â thrig
Jul 18 at 22:25
Thanks for all hints! It just needs to much time to solve this problem - I am working for hours on that. After applying all recommendations to disable buffering (some of them I tried also bevore) and none worked, I am going back to use xargs. It is even an unsupported debian (squeeze - a new hardware is on my table sinde two years ...). Thanks anyone.
â mabra
Jul 18 at 23:26
Thanks for all hints! It just needs to much time to solve this problem - I am working for hours on that. After applying all recommendations to disable buffering (some of them I tried also bevore) and none worked, I am going back to use xargs. It is even an unsupported debian (squeeze - a new hardware is on my table sinde two years ...). Thanks anyone.
â mabra
Jul 18 at 23:26
1
1
I answered the question, but it's really not clear what your desired result is. The
awk
command here does nothing at all. wc
and tail
don't print anything until all data is read. ls
doesn't read stdin at all.â jordanm
Jul 19 at 1:35
I answered the question, but it's really not clear what your desired result is. The
awk
command here does nothing at all. wc
and tail
don't print anything until all data is read. ls
doesn't read stdin at all.â jordanm
Jul 19 at 1:35
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
The reason you do not get output is because wc -l
is consuming all of the output. You can use tee
in combination with process substitution to get awk
to output to the console as well as read by wc
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | tee >(wc -l)
This is still slightly problematic as inotifywait
is a command that never exits, but wc -l
does not print output until it has read all the data, in this case when the pipe closes. You can do your counting directly in awk
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk 'BEGIN total=0 print; total++; print total END print "final total: " total '
1
or use builtinawk 'print;print NR ENDprint "final",NR
â dave_thompson_085
Jul 19 at 5:39
@dave_thompson_085 yeah, that's much better.
â jordanm
Jul 19 at 13:17
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The reason you do not get output is because wc -l
is consuming all of the output. You can use tee
in combination with process substitution to get awk
to output to the console as well as read by wc
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | tee >(wc -l)
This is still slightly problematic as inotifywait
is a command that never exits, but wc -l
does not print output until it has read all the data, in this case when the pipe closes. You can do your counting directly in awk
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk 'BEGIN total=0 print; total++; print total END print "final total: " total '
1
or use builtinawk 'print;print NR ENDprint "final",NR
â dave_thompson_085
Jul 19 at 5:39
@dave_thompson_085 yeah, that's much better.
â jordanm
Jul 19 at 13:17
add a comment |Â
up vote
2
down vote
The reason you do not get output is because wc -l
is consuming all of the output. You can use tee
in combination with process substitution to get awk
to output to the console as well as read by wc
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | tee >(wc -l)
This is still slightly problematic as inotifywait
is a command that never exits, but wc -l
does not print output until it has read all the data, in this case when the pipe closes. You can do your counting directly in awk
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk 'BEGIN total=0 print; total++; print total END print "final total: " total '
1
or use builtinawk 'print;print NR ENDprint "final",NR
â dave_thompson_085
Jul 19 at 5:39
@dave_thompson_085 yeah, that's much better.
â jordanm
Jul 19 at 13:17
add a comment |Â
up vote
2
down vote
up vote
2
down vote
The reason you do not get output is because wc -l
is consuming all of the output. You can use tee
in combination with process substitution to get awk
to output to the console as well as read by wc
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | tee >(wc -l)
This is still slightly problematic as inotifywait
is a command that never exits, but wc -l
does not print output until it has read all the data, in this case when the pipe closes. You can do your counting directly in awk
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk 'BEGIN total=0 print; total++; print total END print "final total: " total '
The reason you do not get output is because wc -l
is consuming all of the output. You can use tee
in combination with process substitution to get awk
to output to the console as well as read by wc
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk ' print ' | tee >(wc -l)
This is still slightly problematic as inotifywait
is a command that never exits, but wc -l
does not print output until it has read all the data, in this case when the pipe closes. You can do your counting directly in awk
:
inotifywait --format="%w%f" -rm /var/log/apache2/ | gawk 'BEGIN total=0 print; total++; print total END print "final total: " total '
answered Jul 19 at 1:32
jordanm
28.8k27690
28.8k27690
1
or use builtinawk 'print;print NR ENDprint "final",NR
â dave_thompson_085
Jul 19 at 5:39
@dave_thompson_085 yeah, that's much better.
â jordanm
Jul 19 at 13:17
add a comment |Â
1
or use builtinawk 'print;print NR ENDprint "final",NR
â dave_thompson_085
Jul 19 at 5:39
@dave_thompson_085 yeah, that's much better.
â jordanm
Jul 19 at 13:17
1
1
or use builtin
awk 'print;print NR ENDprint "final",NR
â dave_thompson_085
Jul 19 at 5:39
or use builtin
awk 'print;print NR ENDprint "final",NR
â dave_thompson_085
Jul 19 at 5:39
@dave_thompson_085 yeah, that's much better.
â jordanm
Jul 19 at 13:17
@dave_thompson_085 yeah, that's much better.
â jordanm
Jul 19 at 13:17
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%2f457096%2fawk-in-the-middle-of-a-pipe-returns-no-output%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
So it still doesn't work with the correct quoting in place?
â Jesse_b
Jul 18 at 22:14
1
turn off buffering (or at least make it line-based) for all the things. unix.stackexchange.com/questions/25372/â¦
â thrig
Jul 18 at 22:25
Thanks for all hints! It just needs to much time to solve this problem - I am working for hours on that. After applying all recommendations to disable buffering (some of them I tried also bevore) and none worked, I am going back to use xargs. It is even an unsupported debian (squeeze - a new hardware is on my table sinde two years ...). Thanks anyone.
â mabra
Jul 18 at 23:26
1
I answered the question, but it's really not clear what your desired result is. The
awk
command here does nothing at all.wc
andtail
don't print anything until all data is read.ls
doesn't read stdin at all.â jordanm
Jul 19 at 1:35