Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想匹配文件中的字符串,打印匹配的行和匹配发生前的第 10 行。我正在尝试使用 awk、sed 和 grep,但无法得到正确的结果。任何人都可以帮忙吗?
试试这个命令:
grep -B 10 PATTERN file.txt
GNU grep的-Aand-B选项允许您指定在匹配行之后和之前应该显示多少上下文。
-A
-B