简体   繁体   中英

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. 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"

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"~'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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