有如下文本
[root@hadoop ~]# cat s.txt
head test
head test again
weihongrao start
this is going
weihongrao is stupy
weihongrao is the ruler
endweihongrao but still going
endweihongrao this is true end
something
nothing
nothing or somthing in test
just test line
假如我需要检索第一次开头出现weihongrao 到最后一次开头出现endweihongrao之间所有的行
[root@hadoop ~]#s=$(grep -n "^weihongrao" s.txt |head -1 |cut -d':' -f1)
[root@hadoop ~]# e=$(grep -n "^endweihongrao" s.txt |tail -1 |cut -d':' -f1)
[root@hadoop ~]# sed -n "${s},${e}p" s.txt
weihongrao start
this is going
weihongrao is stupy
weihongrao is the ruler
endweihongrao but still going
endweihongrao this is true end