Just redirect STDOUT_FILENO
of the tr
process to a newly opened file:
// write-only (as is stdout), truncate to zero length
int file_fd = open("file.txt", O_WRONLY | O_TRUNC);
if (file_fd < 0) {
// error handling
}
if (dup2(file_fd, STDOUT_FILENO) < 0) {
err(EX_OSERR, "dup2 error");
}