user3144292
user3144292

Reputation: 412

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

Upvotes: 1

Views: 71

Answers (1)

anubhava
anubhava

Reputation: 784898

You can use it like this:

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

Upvotes: 1

Related Questions