我正在并且一直在处理 sed 脚本文件,当我运行它时遇到“无效的前面的正则表达式”错误。以下是整个文件。
我已经对此进行了很多搜索,无论是在这个网站上还是在其他地方。这里提出的许多问题导致需要扩展正则表达式,某些东西被错误地转义。我已经将其定义为扩展表达式,因为它是电子邮件替换所需要的。
#!/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's email address.
ServerAdmin/ {
s/\b[A-Za-z0-9._%-]+@(?:[a-zA-Z0-9-]+\.)+(\.[A-Za-z]]{2,4})?\b/email@example.com/
}
#Enable user's 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/
我从 termal 中将其称为 ./config-apache.sed /etc/httpd/conf/httpd.conf 并返回它。
/bin/sed: file ./apache-install.sed line 12: Invalid preceding regular expression
}
vim 第 12 行的内部被标识为上面的单行#Enable user's Public HTML directories