Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy-带“的字符串$&引用;取而代之的是\$_Groovy - Fatal编程技术网

Groovy-带“的字符串$&引用;取而代之的是\$

Groovy-带“的字符串$&引用;取而代之的是\$,groovy,Groovy,如何替换包含$to的文件\$ e、 g 美元文件包含 string 1Mcl0c41$ 更换后应该是这样的 string 1Mcl0c41\$ 使用sed我可以执行 $ cat dollar string 1Mcl0c41$ $ sed "s/1Mcl0c41/1Mcl0c41\\\\/g" dollar > fixed-filename $ cat fixed-filename string 1Mcl0c41\$ 我不想通过使用groovy实现同样的效果,我想用\$替换groo

如何替换包含$to的文件\$

e、 g 美元文件包含

string 1Mcl0c41$
更换后应该是这样的

string 1Mcl0c41\$
使用sed我可以执行

$ cat dollar
string 1Mcl0c41$

$ sed "s/1Mcl0c41/1Mcl0c41\\\\/g" dollar > fixed-filename

$ cat fixed-filename
string 1Mcl0c41\$

我不想通过使用groovy实现同样的效果,我想用\$

替换groovy脚本/程序中出现的所有$,您可以这样说

new File('./fixed-filename') <<  new File('./dollar').text.replace('$','\\$')

这不是您所看到的示例所做的…它将\附加到每个事件的末尾1Mcl0c41@tim但是sed的输出向我显示了所需的结果$cat dollar string 1Mcl0c41$$sed“s/1Mcl0c41/1Mcl0c41\\\\\\\\\/g”dollar>fixed filename$cat fixed filename string 1Mcl0c41\$yeah,但是,用
\$
@Anish替换
\$
并不能做到这一点——我的答案你能接受吗?
groovy -e "line.replace('$','\\\\$')" -p dollars > fixed-filename