Invalid previous regular expression specified by sed

I am working on a sed script file and I run it with the error "Invalid previous regular expression" when I run it. Below is the complete file.

I have already done a lot for this search, both on this site and where. Many of the questions asked here led to the need to either extend regular expressions, or something slipped away incorrectly. I defined this as an extended expression that is already needed to replace email.

#!/bin/sed -rf #/find_this thing/{ #s/ search_for_this/ replace_with_this/ #s/ search_for_this_other_thing/ replace_with_this_other_thing/ #} #Search and replace #ServerAdmin (with preceding no space) email addresses using a regular expression that has the .com .net and so on domain endings as option so it will find root@localhost and replace it in line with admin email address. ServerAdmin/ { s/\b[A-Za-z0-9._%-] +@ (?:[a-zA-Z0-9-]+\.)+(\.[A-Za-z]]{2,4})?\b/ email@example.com / } #Enable user Public HTML directories /UserDir/ { s/disable$/enable/ s/^#User/User/ } #Replace the only #ServerName (with preceding no space) followed space and text with Our server ip /#ServerName */ c\ ServerName server.ip.address.here/ 

I call it from termal like. / config -apache.sed / etc / httpd / conf / httpd.conf and returns it.

 /bin/sed: file ./apache-install.sed line 12: Invalid preceding regular expression 

inside vim line 12 is denoted as single } above #Enable user Public HTML directories

+7
source share
1 answer

GNU sed doesn't seem to like PCRE musical notation:

 ...(?:...)... 

Try:

 s/\b[A-Za-z0-9._%-] +@ ([a-zA-Z0-9-]+\.)+(\.[A-Za-z]]{2,4})?\b/ email@example.com / 

GNU sed looks like this. However, you still have a little work to do. Given the first line below as input, the output is the second line:

 abc def@ghi.jk aaa abc email@example.comjk aaa 

There are two problems giving this result:

  • ]] must be one ] .
  • You are looking for the endpoint in the previous regular expression, so you do not want it in the last part of the domain suffix.

This task:

 s/\b[A-Za-z0-9._%-] +@ ([a-zA-Z0-9-]+\.)+([A-Za-z]{2,4})?\b/ email@example.com / abc def@ghi.jk aaa abc email@example.com aaa 
+13
source