I have a file which is much larger than the amount of memory available on the server which needs to run this script.
In that file, I need to run a basic regex which does a find and replace across two lines at a time. I've looked at using sed, awk, and perl, but I haven't been able to get any of them to work as I need it in this instance.
On a smaller file, the following line does what I need it to:
perl -0777 -i -pe 's/,\s+\)/\n\)/g' inputfile.txt
In essence, any time a line ends in a comma and the next line starts in a closing parenthesis, remove the comma.
When I tried to run that on my production file I just got the message "Killed" in the terminal after a couple of minutes and the file contents were completely erased. I was watching memory usage during that and as expected it was running at 100% and using the swap space extensively.
Is there a way to make that perl command run on two lines at a time instead, or an alternative bash command which might achieve the same result?
If it makes it easier by keeping the file size identical then I also have the option of replacing the comma with a space character.