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.
当我尝试使用以下命令打印包含单词“CHAPTER”的“result.txt”的前 5 行时:
-grep -A 5 "CHAPTER" warandpeace.txt
我不明白我在寻找什么。
我的命令有什么问题?
也许您正在寻找命令:
grep "CHAPTER" warandpeace.txt | head -n 5
它试图找到 的所有实例CHAPTER,但在打印前 5 行后停止。
CHAPTER
如果您的意思是想要前 5 次出现“CHAPTER”,请尝试
grep "CHAPTER" warandpeace.txt | head -5
试一试grep -m 5 "CHAPTER" warandpeace.txt_
grep -m 5 "CHAPTER" warandpeace.txt