Is there a way to modify a file without writing the contents to another file, without sed and awk?For example:$ cat test.txtaaaaaabbbcccdddReplacing using sed with -i option, sed -i 's/aaa/NNN/g' test.txt will produce the following:NNNNNNbbbcccdddHow to do that without awk and sed?
Modify a file without creating another file
files;text processing;scripting
You can use a vi script:$ vi test.txt -c '%s/aaa/NNN/ | wq'$ cat test.txtNNNNNNbbbcccdddYou're simply automating what would normally be entered when using vi in command mode (accessed using Esc: usually):% - carry out the following command on every line:s/aaa/NNN/ - subtitute aaa with NNN| - command delimiterw - write changes to fileq - quit