Jul 10, 2007, 8:41 AM
Post #1 of 1
I have recently started using perl to do regular expression search and replace operations eg.
perl -p -i -e 's/,/\n/g' some.file
to replace all the commas with newline characters in some.file, but I have noticed that often (but not always!) this results in some.file becoming empty. Using the -i switch to generate a back up seems to cure this
perl -p -i.bak -e 's/,/\n/g' some.file
strangely doing a cat of some.file before I run the perl command also seems to prevent the blanking of some.file.
I have a solution that works but I was wondering why the first version is unpredictable.