Bash – Is There a Line-by-Line Bash Pipe?

bashpipe

I remember reading somewhere (then I forgot where) about a rarely used type of bash pipe that could redirect output line-by-line. In other words, rather than redirecting the output once at the end, the output would be redirected for every newline, and run the receiving process multiple times. I've looked in all the bash docs I can get my hands on, but I can't figure out if this 'pipe' really exists.

Is there such a thing as a line-by-line pipe? Of course the task could easily be accomplished other ways, but I'm curious if there is a more elegant way.

Best Answer

I think you are looking for xargs? So say I want to find all the .bak files in a dir and delete them.

find . -name "*.bak" -type f -print | xargs /bin/rm -f

For each file that is found it pipes the result and removes the file.

http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/