/etc/yum.repos.d/CentOS-Base.repo 文件
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
我要添加
使用 sed 在 [base] 部分下的 gpgkey 行之后排除 = postgres* 表达式
sed '/^gpgkey/{s/.*/&\nexclude = postgres*/;:a;n;ba}' /etc/yum.repos.d/CetnOS-Base.repo
不更改文件,我收到错误
sed: -e expression #1, char 16: unterminated `s' command
运行此命令,我是否缺少开关或表达式需要更正?
最佳答案
您似乎正在使用 BSD sed。你可以说:
sed '/\[base\]/,/gpgkey=/{/gpgkey=/s/$/\'$'\n''exclude = postgres*/;}' filename
追加行 exclude = postgres*
之后gpgkey=...
在 [base]
部分。
编辑:说明:
-
/\[base\]/,/gpgkey=/
匹配地址范围,即从包含[base]
的行开始直到包含gpgkey=
的那个 -
{/gpgkey=/s/$/\'$'\n''exclude = postgres*/;}
是一组仅针对上面匹配的地址执行的命令
故障/gpgkey=/s/$/\'$'\n''exclude = postgres*/
:
- 这将执行上述替换
s/$/\'$'\n''exclude = postgres*/
在匹配gpgkey=
的行上. - 以上替换匹配
$
,即行尾。 - 替换为换行符,后跟
exclude = postgres*/
-
$'\n'
是用于生成换行符的 ANSI-C 引用语法。由于您似乎没有使用 GNU sed,因此这是必需的。否则\n
就足够了,即它可以写成/gpgkey=/s/$/\nexclude = postgres*/
关于shell - sed:在基础和更新部分添加排除=postgres*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22932381/