Another user cast the first close vote with the duplicate target. After I looked at the duplicate, I concurred with the other user, and I cast the second close vote, which closed the question (because I have dupehammer powers).
I applied the solution in the duplicate's accepted answer, and it worked for me. I created a short input file for myself, ran the perl
command with the -0777
option, and it properly replaced \nfoo
with bar
in the file. I ran this on Linux because I do not have access to macOS. Here is the exact command I used:
perl -0777 -pi -w -e 's/\nfoo/bar/g;' file
I would like to improve my question, but I do not see a way to do that
I recommend that you edit your question to add more details. For example:
- Add the contents of your input file before you run the
perl
command. It would be best to use 5 lines or less.
- Add the contents of the in-place edited file that you would like to see after you run the
perl
command.
I know nothing about macOS and what newline characters are used. If it uses something different from Linux, then perhaps the newlines get translated into something else when you post your file contents into the question. It may be difficult for people to reproduce. Also, take a look at perldoc perlport.
Your question mentions that the \n
replacement by itself does work, so I don't expect newlines to be a problem.