How to parse output from diskutil activity in bash script


I want to be able to run a bash script over each line output from diskutil activity", I haven't been able to figure out how to do this though.

I thought maybe I could simply:
diskutil activity | xargs bash

I have a feeling that xargs is just going to wait until diskutil activity is finished talking, which it will never do until you end the process.

Any suggestions on how I can execute a script per line of output would be appreciated!


Best Answer

The delay is probably due to buffering.

Try xargs -L 1 bash if you can process the data line by line.