AWK in the middle of a pipe returns no output

The name of the pictureThe name of the pictureThe name of the pictureClash 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!







share|improve this question





















  • 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 and tail don't print anything until all data is read. ls doesn't read stdin at all.
    – jordanm
    Jul 19 at 1:35
















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!







share|improve this question





















  • 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 and tail don't print anything until all data is read. ls doesn't read stdin at all.
    – jordanm
    Jul 19 at 1:35












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!







share|improve this question













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!









share|improve this question












share|improve this question




share|improve this question








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. 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
















  • 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 and tail 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










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 '





share|improve this answer

















  • 1




    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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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 '





share|improve this answer

















  • 1




    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














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 '





share|improve this answer

















  • 1




    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












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 '





share|improve this answer













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 '






share|improve this answer













share|improve this answer



share|improve this answer











answered Jul 19 at 1:32









jordanm

28.8k27690




28.8k27690







  • 1




    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












  • 1




    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







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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay