I'm trying to use perl (v5.14.2) via a bash shell (GNU Bash-4.2) in Kubuntu (GNU/Linux) to search and replace a string that includes a newline character, but I'm not succeeding yet.
Here's the text file I'm searching:
<!-- filename: prac1.html -->
hello
kitty
blah blah blah
When I use a text editor's (Kate's) search-and-replace functionality or when I use a regex tester (http://regexpal.com/), I can easily get this regex to work:
hello
kitty
But when using perl in the command line, none of the following commands have worked:
perl -p -i -e 's,hello
kitty,newtext,' prac1.html
perl -p -i -e 's,hello.kitty,newtext,s' prac1.html
perl -p -i -e 's,hello.*kitty,newtext,s' prac1.html
perl -p -i -e 's,hello[Ss]kitty,newtext,' prac1.html
perl -p -i -e 's,hello[Ss]*kitty,newtext,' prac1.html
Actually, I got desperate and tried many other patterns, including all of these (different permutations in the "single-line" and "multi-line" modes):
perl -p -i -e 's,hello
kitty,newtext,' prac1.html
perl -p -i -e 's,hello.kitty,newtext,' prac1.html
perl -p -i -e 's,hello
kitty,newtext,s' prac1.html
perl -p -i -e 's,hello.kitty,newtext,s' prac1.html
perl -p -i -e 's,hello
kitty,newtext,m' prac1.html
perl -p -i -e 's,hello.kitty,newtext,m' prac1.html
perl -p -i -e 's,hello
kitty,newtext,ms' prac1.html
perl -p -i -e 's,hello.kitty,newtext,ms' prac1.html
perl -p -i -e 's,hello[Ss]kitty,newtext,' prac1.html
perl -p -i -e 's,hello[Ss]*kitty,newtext,' prac1.html
perl -p -i -e 's,hello$[Ss]^kitty,newtext,' prac1.html
perl -p -i -e 's,hello$[Ss]*^kitty,newtext,' prac1.html
perl -p -i -e 's,hello[Ss]kitty,newtext,s' prac1.html
perl -p -i -e 's,hello[Ss]*kitty,newtext,s' prac1.html
perl -p -i -e 's,hello$[Ss]^kitty,newtext,s' prac1.html
perl -p -i -e 's,hello$[Ss]*^kitty,newtext,s' prac1.html
perl -p -i -e 's,hello[Ss]kitty,newtext,m' prac1.html
perl -p -i -e 's,hello[Ss]*kitty,newtext,m' prac1.html
perl -p -i -e 's,hello$[Ss]^kitty,newtext,m' prac1.html
perl -p -i -e 's,hello$[Ss]*^kitty,newtext,m' prac1.html
perl -p -i -e 's,hello[Ss]kitty,newtext,ms' prac1.html
perl -p -i -e 's,hello[Ss]*kitty,newtext,ms' prac1.html
perl -p -i -e 's,hello$[Ss]^kitty,newtext,ms' prac1.html
perl -p -i -e 's,hello$[Ss]*^kitty,newtext,ms' prac1.html
(I also tried using
R f D etc., and global mode as well.)
Can anyone spot the issue or suggest a solution?
See Question&Answers more detail:
os