I am trying to replace all digits sequences followed by a line feed and the letter
a
test.txt
command.sh
00
a1
b2
a
#!/bin/bash
MY_VAR="\d+
a"
grep -P "^.+$" test.txt | perl -pe "s/$MY_VAR/D/";
command.sh
$ ./command
00
a1
b2
a
$ ./command
D1
bD
You don't even need grep
since it is just matching .+
, just use perl
with -0777
option (slurp mode) to match across the lines:
#!/bin/bash
MY_VAR="\d+
a"
perl -0777pe "s/$MY_VAR/D/g" test.txt
Output:
D1
bD