sed - 使用 sed 命令添加 debian 存储库
问题描述
我想通过配置自动生成我的 debian 系统 virtualbox。我必须安装非标准或默认的 PHP 环境。我必须添加存储库 dotdeb以查找 5.3 版本的特殊包 PHP。
我的 shell 配置脚本必须编辑 /etc/apt/sources.list 以添加与 dotdeb 存储库对应的行。这一行是:
deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all
如何使用 sed 命令编辑我的文件以获得以下结果:
#
# deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main
#deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main
deb http://httpredir.debian.org/debian wheezy main
deb-src http://httpredir.debian.org/debian wheezy main
deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main
deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all
/etc/apt/sources.list 的默认内容文件是:
#
# deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main
#deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main
deb http://httpredir.debian.org/debian wheezy main
deb-src http://httpredir.debian.org/debian wheezy main
deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main
最后,我只想在文件末尾添加一个空行,然后添加到特定行。但是我没有找到如何在文件末尾添加空行并使用 sed 命令添加具有多个特殊字符的特定行...
解决方案
sed -i '$ a\\ndeb http://packages.dotdeb.org wheezy all\ndeb-src http://packages.dotdeb.org wheezy all' /etc/apt/sources.list
推荐阅读
- matlab - 如何使用函数从任何方阵中获取所有子矩阵(2x2),然后从子矩阵中创建一个具有最大值的新矩阵
- python - Heroku Django 邮件未发送
- php - PHP htaccess URL 重写
- docker - 使用 Travis 时挂载的 Docker 卷具有不同的所有权
- java - 计步传感器不适用于真实设备
- laravel - Laravel 8 错误路径 | 此路由不支持 GET 方法
- python - bacnet_scan 输出 csv 文件错误 TypeError: a bytes-like object is required, not 'str'
- java - 如何计算随机数组中出现的次数?
- python - StyleFrame 插件不尊重 number_format
- java - 如何将 Telosys 存储库添加为 Maven 依赖项?