SED:需要使用“/"在字符串中使用 sed 追加 [英] SED: Need to use "/" in string to append using sed

查看:57
本文介绍了SED:需要使用“/"在字符串中使用 sed 追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构造包含/"字符的 SED 命令.sed 不认为此命令有效:

I need to construct SED command that contains "/" character. sed is not consedering this command as valid:

添加约翰/街道"

String cmdtest[] = {"sed","-3 a" + "\\","> john\\/street","/scratch/tmp.txt"};

我还需要知道如何替换包含/"的字符串.

also I need to know how can I go for replacing a string that has "/" included.

这是我需要执行的

cmdtest[] = {"sed","-i","s/ee.jar:/ee.jar:$MY_HOME\\\/lib\\\/jcagent.jar","/scratch/myreg.sh"};

输出应将文件 myreg.sh 中的 {ee.jar} 替换为 {ee.jar:$MY_HOME/lib/jcagent.jar}

Ouptput should replace {ee.jar} with {ee.jar:$MY_HOME/lib/jcagent.jar} in file myreg.sh

推荐答案

你可以在 sed 中使用任何其他字符作为分隔符而不是/,然后你可以将/放在字符串中而不需要任何转义,例如这是有效的 sed命令:sed -e 's#something/#something#'将某事/"替换为某事"

you can use any other char as delimiter instead of / in sed, and then you can put / in the string without any escaping, for example this is valid sed command: sed -e 's#something/#something#' that will replace 'something/' with 'something'

这篇关于SED:需要使用“/"在字符串中使用 sed 追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆