Here's the self-explanatory one-liner I want to execute:
for f in *; do awk '{sub(FILENAME, FILENAME".")1}' $f > $f; done
This command does not work as wanted. The output files are all empty. I have searched the internet for the reason that happens, and it turns out loops in Bash are considered one single command, thus stream redirection is expected to be outside of it, after "done"
I then tried this, and the result is even more surprising:
for f in *; do awk '{sub(FILENAME, FILENAME".")1}' $f | tee $f; done
So now does not work too, except sometimes it does for one of the files in the directory, not the same. I copy over fresh copies of the files in the directory (that I have backed up somewhere else), I run that one-liner, and file B is modified as expected (others become empty). Then I recopy over fresh copies, rerun the command, then it's file C that gets modified as expected (others still empty). And some other times, it won't work for even one file.
- Can you please tell me how I can achieve the desired result?
- What is happening with that second command?