Loading

linux基础命令grep显示前后

通过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>


posted @ 2022-09-28 11:30  萝卜青菜~  阅读(198)  评论(0编辑  收藏  举报