Hello I am trying to do a replace on a file where a string is followed by any random string using sed. My original file looks like below.
access = read : [ * ], write : [ admin, sc_admin ]
access = read : [ * ], write : [ admin, myuser ]
access = read : [ * ], write : [ admin ]
access = read : [ * ], write : [ admin, randomuser ]
access = read : [ * ], write : [ admin, randomuser, somedude ]
access = read : [ * ], write : [ admin, justarandomuser, somedude, anotherdude ]
access = read : [ * ], write : [ admin, another_random_user ]
I need to add a string called sc_admin after my random user which follows admin so that it looks like this
access = read : [ * ], write : [ admin, sc_admin ]
access = read : [ * ], write : [ admin, myuser, sc_admin ]
access = read : [ * ], write : [ admin ]
access = read : [ * ], write : [ admin, randomuser, sc_admin ]
access = read : [ * ], write : [ admin, randomuser, somedude, sc_admin ]
access = read : [ * ], write : [ admin, justarandomuser, somedude, anotherdude, sc_admin ]
access = read : [ * ], write : [ admin, another_random_user, sc_admin ]
I am trying to run the following sed command but its not doing anything.
sed -r "s/\[\ admin\,\ \w+\ \]/\[\ admin\,\ \w+\,\ sc\_admin\ \]/g" local.meta
what am i missing here?
adminfollowed byrandomuserorrandom_useradminuser? If so include one of those in your question so we can see how they should be handled.access = read : [ * ], write : [ admin, mollusc_administered ]for example (they'd fail because it contains the substringsc_admin) . Take a minute to think about cases where a script might fail (e.g. false matches on substrings, regexp instead of string matches) and add those to your example.