[英]sed substitution is not working with variable
猫文件.txt
...Some random string...
...String random string...
service_account_file = $HOME/easyclone/accounts/1.json
...Some random string...
...Some random string...
我只需要用预定义变量的值替换第 3 行的结尾部分(在这种情况下为 1,即 string.json 之前的数字)
rjc1=999 && sed -i "3s/*\.json/$rjc1\.json/" file.txt
我尝试了上面的命令,打算用 999.json 替换 1.json 但它似乎不起作用
具有上述变量值的预期结果
...Some random string...
...String random string...
service_account_file = $HOME/easyclone/accounts/999.json
...Some random string...
...Some random string...
谁能帮我解决这个小问题
笔记:
sed -ri "3s/[[:digit:]]+\.json/$rjc1.json/" file
在第三行,替换一个或多个数字,然后用“.json”替换 rjc1 变量,后跟“.json”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.