通过grep查找字段后,方便查看前后文本
grep -C 8 '中央仓库在中国的镜像' settings.xml
显示指定行的上线8行
[root@znjc-ds-zcfwserv conf]# grep -C 8 '中央仓库在中国的镜像' settings.xml
<mirror>
<id>google-maven-central</id>
<name>Google Maven Central</name>
<url>https://maven-central.storage.googleapis.com
</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- 中央仓库在中国的镜像 -->
<mirror>
<id>maven.net.cn</id>
<name>oneof the central mirrors in china</name>
<url>http://maven.net.cn/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
显示指定行前8行
[root@znjc-ds-zcfwserv conf]# grep -B 8 '中央仓库在中国的镜像' settings.xml
<mirror>
<id>google-maven-central</id>
<name>Google Maven Central</name>
<url>https://maven-central.storage.googleapis.com
</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- 中央仓库在中国的镜像 -->
显示指定行后8行
[root@znjc-ds-zcfwserv conf]# grep -A 8 '中央仓库在中国的镜像' settings.xml
<!-- 中央仓库在中国的镜像 -->
<mirror>
<id>maven.net.cn</id>
<name>oneof the central mirrors in china</name>
<url>http://maven.net.cn/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
标签:xml,central,cn,前后,maven,linux,grep,net
From: https://www.cnblogs.com/gkmin/p/16737418.html