0

I'm trying to redirect the output of a tr command to a file, after piping a sed command to tr. The pipe is:

sed "1a|.\ $0" $script_file | tr '|' '\n' # this works

(About the use of tr: could not find another way to append linebreaks with sed; all the other solutions involve adding '\' and linebreaking in my script, within sed command or in a variable that is used in sed command.)

The output is ok, but when I try to redirect it, it empties my input file.

sed "1a|.\ $0" $script_file | tr '|' '\n' > $script_file # this doesn't work

Any ideas of why this is happening?

Try: to redirect the output of a sed and tr piping to the same file that is read by sed. Expect: to redirect the output of sed and tr commands without having to create/delete a temporary file (this is the solution I came with, but seems lazy); also, to understand why this is happening.

0 Answers0