-1

This question already has an answer here:

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.

marked as duplicate by Gilles bash Jun 5 '15 at 22:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 5 '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 5 '15 at 20:11
  • It's rsync that buffers, not awk. – Gilles Jun 5 '15 at 22:59
0

Ended up using mawk -Winteractive

Not the answer you're looking for? Browse other questions tagged or ask your own question.