I have a file called “test.txt” like that:
hello world
it is, just a ‘hello world’ string. If I use a perl regex:
perl -pe "s/hello/bye/g" test.txt
it says:
bye world
but if I try to redirect that file to itself:
perl -pe "s/hello/bye/g" test.txt > test.txt
the resulting file is empty. Why? And how can I ‘filter’ a regex over a file?
perlaccepts the parameter-ifor inplace. With this, you can process a file with a perl program and immediately have it written back.