【问题标题】:add debian repository with sed command使用 sed 命令添加 debian 存储库
【发布时间】:2018-09-20 10:07:16
【问题描述】:

我想通过配置自动生成我的 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?这对于标准的cat 来说是一件容易的事。
  • 你如何使用 cat 命令@IporSircer
  • @darkomen,您是否只想在 Input_file 的最后输入一个新行?或者您需要做的任何具体线路,请确认。
  • 您可以/应该在/etc/apt/sources.list.d 中创建一个新文件,而不是向/etc/apt/sources.list 添加行。然后你不需要编辑任何东西,只需在那里创建/复制文件。如果需要,也可以更轻松地在以后删除它。

标签: sed debian


【解决方案1】:
sed -i '$ a\\ndeb http://packages.dotdeb.org wheezy all\ndeb-src http://packages.dotdeb.org wheezy all' /etc/apt/sources.list

【讨论】:

    【解决方案2】:

    如果您只是想在 Input_file 的最后添加一个新行,请执行以下操作。

    echo "" >> Input_file
    

    【讨论】:

      猜你喜欢
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 2010-09-09
      相关资源
      最近更新 更多