4

How do I pass some input to a command line by line (ie. invoke the command for every line)?

xargs does not work because it passes the lines as arguments, not as standard input.

The specific case where this came up was decoding a file whose lines were base64-encoded strings.

Tgr
  • 2,953
  • 4
  • 26
  • 31

1 Answers1

9

Can be done with a while loop:

produce | while IFS= read -r line; do echo "$line" | process; done | consume

(for some arbitrary produce, process, consume commands which all use standard input/output) but meh. There has to be a more elegant way of doing it.

Tgr
  • 2,953
  • 4
  • 26
  • 31