This question already has an answer here:
- How to replace multiple any-character (including newline) in Perl RegEx? 1 answer
I am trying to replace all digits sequences followed by a line feed and the letter a
. Those digits sequences are located in a file called test.txt
. The bash script command.sh
is used to perform the task (see below).
test.txt
00
a1
b2
a
command.sh
#!/bin/bash
MY_VAR="\d+
a"
grep -P "^.+$" test.txt | perl -pe "s/$MY_VAR/D/";
When I call the command.sh
file, here is what I see:
$ ./command
00
a1
b2
a
However, I'm expecting this output:
$ ./command
D1
bD
What am I missing?