<分区>
我正在尝试替换所有数字序列,后跟换行符和字母 a
。这些数字序列位于名为 test.txt
的文件中。 bash 脚本 command.sh
用于执行任务(见下文)。
测试.txt
00
a1
b2
a
command.sh
#!/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
我错过了什么?