0

How to replace below text with an empty line in a config file?

# + : STANDANRD\ADMIN_USERS_ONLY : ALL

1 Answers1

0
sed -i 's/# + : STANDANRD\\ADMIN_USERS_ONLY : ALL//g' config_file

should do the trick. Note the double backslash which is important since a backslash followed by a character has a special meaning to the regex parser. These meta characters are shortcuts for things like a whitespace (\s), an alphanumeric character (\w) or in the case of \A the beginning of a string (the Regular Expression Wikipedia article has a table summarizing the most popular meta characters). Since backslash has this special meaning you have to type a double backslash if you want to match a single backslash in your file.

Example output on CentOS 7:

[tux@centos7 ~]$ cat config_file 
# + : STANDANRD\ADMIN_USERS_ONLY : ALL foo
[tux@centos7 ~]$ sed -i 's/# + : STANDANRD\\ADMIN_USERS_ONLY : ALL\(.*\)/\1/g' config_file
[tux@centos7 ~]$ cat config_file 
 foo