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 @   萝卜青菜~  阅读(202)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
点击右上角即可分享
微信分享提示
主题色彩