bash - 从shell脚本中的行首删除字符?

标签 bash shell ubuntu

我正在编写一个 shell 脚本来自动设置 apache 网站的配置和目录。我遇到了一个问题,我的 sed命令不会删除默认 #从 ServerName 行的开头。谁能帮我更改命令以按照我需要的方式工作?

谢谢。

sudo sed -Ei "s|^([[:blank:]]*#ServerName).*$|\1 ${1.io|;
         s|^([[:blank:]]*DocumentRoot).*$|\1 \"/var/www/${1}/public\"|;
        " "/tmp/${1}.io.conf"

最佳答案

为什么该命令要删除哈希?它是您的捕获组的一部分。

如果你想删除它,split the capturing group in two parts : 一个在哈希之前,一个在它之后。

^([[:blank:]]*)#?(ServerName).*$

关于bash - 从shell脚本中的行首删除字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56003958/

相关文章:

php - Ubuntu Apache : "Module php7 does not exist"

linux - 如何正确地将 unix top 命令输出保存到变量中?

bash - 如何在不注销/登录的情况下将用户添加到组 - Bash 脚本

bash - Debian 8.11 上的 wg-quick "wait: pid 9185 is not a child if this shell"

performance - MongoDB限制内存

ubuntu - 使用 AutoKey 读取数字很慢

linux - 安装的 .desktop 文件插入用户的主目录路径

json - 将多个变量而不是文件传递给 jq 命令

android - adb -d shell "run-as ..."不适用于 Android O

perl - 调试 Perl 脚本