dark templar
dark templar

Reputation: 3

Sed replace string with special characters

I am trying to replace the below indicated string with special characters in a file, in linux. I tried using the backslash in front of every special char, but getting errors. Must be missing something. How do I achieve the below. Thanks in advance:

filter = [ "a/sda[0-9]*$/",  "r/sd.*/" ]   ---> Replace this line with below line

filter = [ "a/sda[0-9]*$/", "a/sdb[0-9]*$/", "r/sd.*/" ]

Upvotes: 0

Views: 2409

Answers (2)

Gilles Quénot
Gilles Quénot

Reputation: 185881

Using and columns strategy :

$ awk '{$3=$3 "a/sdb[0-9]*$/\042, "; print}' file.txt
filter = [a/sdb[0-9]*$/",  "a/sda[0-9]*$/", "r/sd.*/" ]

Upvotes: 0

Kent
Kent

Reputation: 195289

for your example, this worked

sed 's@",@", "a/sdb[0-9]*$/",@' 

output:

kent$  echo 'filter = [ "a/sda[0-9]*$/",  "r/sd.*/" ]'|sed 's@",@", "a/sdb[0-9]*$/",@'                                                         
filter = [ "a/sda[0-9]*$/", "a/sdb[0-9]*$/",  "r/sd.*/" ]

Upvotes: 1

Related Questions