I was trying sed
to replace some keywords in a large file (100 MB). I was unaware of the -i
(inplace) option, so my first attempt was to redirect like this:
sed 's/original/edited/g' file.log >> file.log
what happened after that was that my PC went to a halt, almost no keyboard input. I tried a different console Ctrl + Alt + F1 but after slowly entering user name, it halted too. Without keyboard, my only option was to hardware-reset the machine. After logging in, I saw that file.log was about 8 GB.
I really would like to understand why the execution of that command was able to make the system so unresponsive, and if mechanisms exist at the system level to trigger alerts and kill the offending process?
free -h
?ex -sc '%s/original/edited/ge|x' file.log
should do what you want in a UNIX idiomatic way without thesed -i
side effects.