0

I'm trying to follow this answer but I can't make it work.

I simplified it down as much as I could to try work out what's going on (just running this at the terminal for now):

rsync --progress -iav /my/dir1 /my/dir2 | awk '{ print($0) }'

But it only prints messages likersync: failed to set times on [file].

What am I doing wrong?

Edit: On further investigation it seems like awk is doing some sort of buffering. This:

for i in 10 20 30; do echo $i; sleep 1; done | awk '{print $0}'

Demonstrates a problem where no output is seen until 3 seconds have passed.

So I guess the question is how do I get awk to flush its buffer? I tried:

for i in 10 20 30; do echo $i; sleep 1; done | awk '{print($0); fflush()}'

Which had the same problem.

  • Please [edit] your question and explain what you're trying to do. What's the point of awk '{print $0}'? That will just print the input line. Are you trying to remove the buffering? What is your actual objective? Also, please always mention which operating system and what version of awk you are using. Is this on Linux? Unix? OSX? – terdon Jun 05 '15 at 16:39
  • On further investigation it seems like awk is doing some sort of buffering - awk is not buffering anything. It's the pipe which populates STDIN of the right hand side command only when the left hand side commad has finished executing. And this is not a problem. This is how it's supposed to be. I do not see a point in the whole thing you did. – Soumyadip DM Jun 05 '15 at 20:11
  • It's rsync that buffers, not awk. – Gilles 'SO- stop being evil' Jun 05 '15 at 22:59
  • I just encountered the same issue with mawk: fflush() or fflush("") don't seem to do anything. I'm glad there's a work-around with -W interactive – Adrian Pronk Aug 14 '22 at 22:49

1 Answers1

0

Ended up using mawk -Winteractive