Issue running sed to replace a string in file

I am trying to run the following sed command on this line:

entry({"servicectl"}, alias("servicectl", "status")).sysauth = "Admin"

sed -i~ -e '18 { s/= "(.*)"/= {""}/; # Add curlies to a single entry.
                 s/}/,"'"$entry"'"}/     # Add the new entry.
                }' "$file"

I want to replace "Admin" with {"Admin", "$entry"}

THe problem I see is in the Regular expression to search is "(.*)"

The command was originally designed for A line which contains:

page.sysauth = "Admin"   ---> changes to page.sysauth = {"Admin", "$entry" }

Also Assuming that I am able to add an entry then I would like to remove it as well.

sed -i~ -e '18 { s/"'"$entry"'"//;      # Remove the entry.
                 s/,}/}/;               # Remove the trailing comma (entry was last)
                 s/{,/{/;               # Remove the leading comma (entry was first)
                 s/,,/,/;               # Remove surplus comma (entry was inside)
                 s/{"([^,]*)"}/""/  # Remove curlies for single entry.
                 }' "$file"

That is if the entry is : {"Admin", "$entry"}

Then upon removal it should become : "Admin"


Source: bash

Leave a Reply