简体   繁体   English

如何替换bash脚本

[英]how to replace line bash script

I'm looking to replace a line of text in a file. 我正在寻找替换文件中的一行文本。 This is not a specific line #, but rather matching a certain parameter and then replace the entire line with what I want. 这不是特定的行号,而是匹配某个参数,然后用我想要的内容替换整行。

Looking into 'sed' seems to be an idea, problem is all the special chars included in the source/to replace strings that are confusing me in sed how to handle properly. 研究“ sed”似乎是一个主意,问题在于源代码中包含的所有特殊字符/用于替换使我困惑sed如何正确处理的字符串。 I also tried these are parsed variables but with no results. 我也尝试过这些是解析变量,但没有结果。

Eg: Source line to match: PATH_FLOW=*ANYTHINGgoes* To be replaced with: PATH_FLOW="file:///var/log" 例如:要匹配的源代码行: PATH_FLOW=*ANYTHINGgoes*要替换为: PATH_FLOW="file:///var/log"

sed -i 's/^PATH_FLOW=*/PATH_FLOW="file:///var/log"/g' /etc/sysconfig/random_file

您可以像这样使用它:

sed -i.bak '/PATH_FLOW=/s~^.*$~PATH_FLOW="file:///var/log"~'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM