1

When typing such a command:

find . -type f -iname "*part*"

I get, slowly, file names appearing, as soon as they're found -- one at a time.

Adding a sed expression behind it...

find . -type f -iname "*part*" | sed "s#^\./##"

… delays the display up to the end of the find command, then processing everything at once.

How to avoid that? How to flush to sed?

PS- Alternatively, how to remove the ./ prefix from every line, without delaying the display?

user3341592
  • 1,419
  • 1
  • 17
  • 36
  • 3
    [How to make output of any shell command unbuffered?](https://stackoverflow.com/q/3465619/608639), [Unbuffered Bash Output](https://stackoverflow.com/q/27257320/608639), [Turn off buffering in pipe](https://unix.stackexchange.com/q/25372), [Force flushing of output to a file while bash script is still running](https://stackoverflow.com/q/1429951/608639), [How to correctly unbuffer a pipeline?](https://unix.stackexchange.com/q/386987) and friends. – jww Nov 10 '19 at 13:19
  • Use `find . -type f -iname "*part*" -printf '%P\n'` to strip the `./` prefixes at the source. – John Kugelman Nov 10 '19 at 13:44
  • @JohnKugelmansupportsMonica Thanks a lot! That did it. For whichever reason which escapes me, none of the awk / stdbuf solutions did work -- they still delayed the sed up to the end. Your solution solves this. (Any idea why stdbuf did not work?) – user3341592 Nov 10 '19 at 13:52
  • 1
    Did you apply `stdbuf -oL` to `find`? – John Kugelman Nov 10 '19 at 13:59
  • I did `find … | stdbuf -oL sed …` – user3341592 Nov 10 '19 at 14:44
  • Apply it to `find` instead. The buffering is on the output side of the pipe not the input side. – John Kugelman Nov 10 '19 at 14:55
  • You're completely right: `stdbuf -oL find … | sed …`does the job. Thanks a lot for this information! (and your better solution) – user3341592 Nov 10 '19 at 19:54

0 Answers0