/etc/yum.Storage.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我想补充一下
exclude = postgres*在gpgkey行之后使用sed在基节下使用表达式
sed '/^gpgkey/{s/.*/&\nexclude = postgres*/;:a;n;ba}' /etc/yum.repos.d/CetnOS-Base.repo不更改文件,则会出现错误。
sed: -e expression #1, char 16: unterminated `s' command运行此命令时,是否缺少一个开关或表达式需要更正?
发布于 2014-04-08 09:29:53
你好像在用BSD。你可以说:
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引用语法,用于生成换行符.因为您似乎没有使用GNU,所以这是必需的。否则\n就足够了,即它可以写成/gpgkey=/s/$/\nexclude = postgres*/发布于 2014-04-08 09:10:42
在单独的}块中尝试使用-e内联sed:
sed -i.bak -e '/^gpgkey/{s/.*/&\nexclude = postgres*/;:a;n;ba;' -e '}' /etc/yum.repos.d/CetnOS-Base.repo发布于 2014-04-08 09:13:32
你可以用这个sed,
sed '/\(\[base\]\|\[updates\]\)/,/gpgkey/{/gpgkey/s/.*/&\nexclude=postgres*/}' /etc/yum.repos.d/CetnOS-Base.repohttps://stackoverflow.com/questions/22932381
复制相似问题