EditInPlace

You cannot edit a file in place with awk. What you should do is direct your output to a temporary file, and, if everything is fine, rename the temporary file:

awk '{do whatever}' originalfile.txt > tmpfile.txt && mv tmpfile.txt originalfile.txt

If you have special requirements, you can of course use something more sophisticated like mktemp to create the temporary file.

(and, by the way, sed or perl, when given the -i option, create a temporary file behind the scenes and then rename it anyway).

If you are brave and are happy at the idea of losing your data in case of a crash happening while the program is running, you can do something like this:

awk '{do whatever;line[NR]=$0}
END{close(ARGV[1])
    for(i=1;i<=NR;i++){
      print line[i] > ARGV[1]
    }
   }' originalfile.txt