gpt4 book ai didi

grep 查找字符串,获取前后行,不显示行号

转载 作者:行者123 更新时间:2023-12-02 00:26:23 24 4
gpt4 key购买 nike

最近我需要在文件中搜索特定字符串,并且需要显示匹配项之前的行和之后的行。

文件

AAAABBBB                      CCCCDDDD

Using google I found the following solution utilizing grep.

grep -n1 BBBB File

哪些输出,

1-AAAA
2-BBBB
3-CCCC

所以这符合我想要的,除了它在输出中显示行号。

有没有办法抑制行号?

最佳答案

使用这个:

grep -C 1 BBBB input

grep 具有三个用于显示上下文行的选项:

  -A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing -- between contiguous groups of
matches.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing -- between contiguous groups of
matches.
-C NUM, --context=NUM
Print NUM lines of output context. Places a line containing -- between contiguous groups of matches.

关于grep 查找字符串,获取前后行,不显示行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17077634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com