When I do my_script < filename.txt > filename.txt
, the file is overwritten and truncated.
Is there some way on the Unix command line to specify that redirection is not done concurrently, i.e. the output does not begin until the input has completed?
I am trying to write a utility that reads a file, and based on the command line options, regenerates and overwrites it. I realize I could add support in the program for not using stdin/stdout, but I like the flexibility and convenience of redirection.
-o outputfile
, as insort
. Or usesponge
– ilkkachu Sep 16 '21 at 21:48cat file.txt | sponge > file.txt
) and the file is still empty after the command is executed. – Keith Bennett Sep 16 '21 at 22:11sponge file.txt
. This is shown on the man page. Please learn to look at the man page for a program you want to use or at least one you are having trouble with. Or just follow the link @ikkachu gave to a previous Q -- you did notice your browser shows that word is a hyperlink, right? – dave_thompson_085 Sep 17 '21 at 00:57