SED:显示前10行复杂表达式

use*_*244 1 linux bash sed

如何使用sed查找单词linux的行?后来用linux这个词显示第一行10?EX:

cat file | sed -e '/linux/!d' -e '10!d' ### I can not display the first 10 lines of the word linux

cat file | sed '/linux/!d' | sed '10!d' ### It is well
Run Code Online (Sandbox Code Playgroud)

如何让它与一个sed一起工作?

cat file | sed -e '/linux/!d; ...?; 10!d'
Run Code Online (Sandbox Code Playgroud)

...? - 存储缓冲区linux?10后来切线?

有人向我解释?

hek*_*mgl 5

我会用awk:

awk '/linux/ && c<10 {print;c++} c==10 {exit}' file
Run Code Online (Sandbox Code Playgroud)

  • +1:或`awk'/ linux/&& c ++ <10; c == 10 {exit}'file` (2认同)
  • @JS웃是的!看起来更好:) awk rocks !!! 将保留我的答案,以便其他人仍然可以看到你的答案如何缩短. (2认同)