Question: How can I combine the following two commands:

```
find . -print0 | grep -z pattern | tr '\0' '\n'
find . -print0 | grep -z pattern | xargs -0 my_command

```

into a single pipeline? If I don't need NUL separators then I can do:

```
find . | grep pattern | tee /dev/tty | xargs my_command

```

I want to avoid using a temporary file like this:

```
find . -print0 | grep -z pattern > tempfile
cat tempfile | tr '\0' '\n'
cat tempfile | xargs -0 my_command
rm tempfile

```

This question is a follow-up to these answers:

1) Using /dev/tty to display intermediate pipeline results:

<https://unix.stackexchange.com/a/178754/8207082>

2) Using a NUL-separated list of files:

<https://stackoverflow.com/a/143172/8207082>

Edited to use `my_command` instead of `command`.

Follow-up question:

[Makefile rule that writes to /dev/tty inside a subshell?](https://stackoverflow.com/questions/44731163/)

Answer: 
One of the possibilities:

```
find . -print0 | grep -z pattern | { exec {fd}> >(tr '\0' '\n' >/dev/tty); tee "/dev/fd/$fd"; } | xargs -0 command

```

Where we create a temporary file descriptor `fd` with `exec` on fly which is connected to `tr`'s stdin via standard process substitution. `tee` passes everything to stdout (ending on `xargs`), and a duplicate to a `tr` subprocess that outputs to `/dev/tty`.
It's possible to execute multiple commands with xargs like so:

```
find . -print0 | grep -z pattern | xargs -0 -I% sh -c 'echo "%"; command "%"'

```

Source:

<https://stackoverflow.com/a/6958957/8207082>

Per discussion, the above is unsafe, this is much better:

```
find . -print0 | grep -z pattern | xargs -0 -n 1 sh -c 'echo "$1"; my_command "$1"' _

```