I have several hundred readme files which follow a specific format. I need to replace a chunk of text in each one with different content. Everything is working great except I'm unable to select the words if there are newlines \n
between the words. An example is as follows:
...
this
is
old
content
...
I would like to replace all the text in these files so they look like this
...
new content
...
I have tried the following perl commands but they do not work with the newlines
perl -pi -w -e 's/this(\n|.)*?content/new content/g;' *.txt
I have tried adding the /s tag based on https://stackoverflow.com/a/226601/4975772 (perhaps I'm doing this incorrectly..)
perl -pi -w -e 's/this(\n|.)*?content/new content/gs;' *.txt
Without the "?"
perl -pi -w -e 's/this(\n|.)*content/new content/g;' *.txt
Using (.+?) instead of (\n|.) based on Regex to match any character including new lines
perl -pi -w -e 's/this(.+?)*content/new content/g;' *.txt
Using [\s\S] instead of (\n|.) based on Regex to match any character including new lines
perl -pi -w -e 's/this[\s\S]*content/new content/g;' *.txt
I have tried these expressions inside regexpal.com and they reportedly work perfectly.
If I remove the newlines from the readme files, everything works perfectly for all of these example perl commands. What am I doing wrong?