For example, here's my command I'm using:tr -d '\n' < newfile.ppm I want to output the results to that exact same file, so I am now doing:tr -d '\n' < newfile.ppm > newfile.ppmWhy is this not working and how can I get it to work?
Why am I unable to save my output to a file from a command that takes input as the file itself?
text processing;io redirection;command
This is an extremely common gotcha. When you redirect stdout or stderr to write to a file, the shell will first truncate the file to prepare it for writing. So what's occurring is roughly the following:Your shell sets stdin to newfile.ppmYour shell truncates newfile.ppm to length 0Your shell sets stdout to newfile.ppmYour shell runs tr -d '\n'. As you can see, at this point, the contents of newfile.ppm are already gone, so there is nothing to read.To work around this, just output to another file instead. You can then rename it afterwards