I have a grep -o '100%'
piped after a wget
, so I'm only notified that wget
completed the download, without useless information on screen. But each 100%
is printed on a new line, and I don't like this flood! So, is there a way to tr
the newlines into spaces, by piping tr
after grep
? All I got was no result, each time I tried...
Add a comment
|
2 Answers
You would have gotten output eventually, but all in one go. This is due to buffering.
GNU grep
has a --line-buffered
to avoid output buffering. tr
does input buffering with no apparent way to turn it off, so you can use awk
instead:
wget -r -l 1 http://stackoverflow.com/ 2>&1 |
grep --line-buffered -o '100%' | awk '{printf("%s ", $0);}'
100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100%
-
"You would have gotten output eventually, but all in one go." True, I confirmed now. I have not waited long because there were a lot of files to download, and it's very annoying to look at a screen that has no information about what is happening!– user4863385Commented Aug 9, 2016 at 22:11
-
Are you sure that
--line-buffered
disables buffering? Bothman
andinfo
says otherwise: "Use line buffering on output.". By the way, using it or not gives the same result: all100%
only at the end.– user4863385Commented Aug 9, 2016 at 22:29 -
Are you trying the command as provided here or did you just add
--line-buffered
to your existing command? Commented Aug 9, 2016 at 22:45 -
I followed your instructions, but only after the
wget
. So I maintained mywget
(not recursive, input from file) and added what you suggested. Anyway, now I tested exactly what you suggested, except without the line break betweenwget
andgrep
, and there was no100%
until I aborted the process for taking too long without any output, and noticing that the download stopped at 18 items on the folder.– user4863385Commented Aug 10, 2016 at 0:03 -
That's pretty strange and I can't reproduce it. How about if you use
stdbuf -oL wget ...
? Commented Aug 10, 2016 at 2:22
It's buffering, see Why no output is shown when using grep twice?. Just use awk:
$ wget -r -l 1 https://stackoverflow.com/ 2>&1 | awk 'match($0,/100%/){printf "%s ", substr($0,RSTART,RLENGTH)}'
100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100%
or probably more useful:
$ wget -r -l 1 https://stackoverflow.com/ 2>&1 | awk '/100%/{printf "."}'
...........
-
I copied and executed the commands as they were written by you. Both downloaded 18 items, gave no output, and needed to be canceled (CTRL+C) to stop executing. I think, with this repeating to more than 1 solution of more than 1 replier, that other things needs to be checked. On which version of
wget
your solution worked?– user4863385Commented Aug 10, 2016 at 5:00 -
-
I was on 1.17.1, so I updated to 1.18 and tried again. Same non-results... So it's not
wget
the culprit. Maybeawk
? Here it's being caled mawk by man and info.– user4863385Commented Aug 10, 2016 at 21:01 -