This question already has an answer here:
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?
You don't even need
grep
since it is just matching.+
, just useperl
with-0777
option (slurp mode) to match across the lines:Output: