【求助】文本抓取

sh/bash/dash/ksh/zsh等Shell脚本
回复
halfwolf
帖子: 40
注册时间: 2012-01-28 21:27

【求助】文本抓取

#1

帖子 halfwolf » 2014-09-29 14:52

我要处理的文件中有大量的task块,需要将该块抓取出来,请各位高人帮忙

cat myfile
--------------
other content

task task_name1
Description
…………………………
endtask

other content

task task_name2
Description
…………………………
endtask

抓取结果为干干净净的task块,如下
task task_name1
Description
…………………………
endtask
task task_name2
Description
…………………………
endtask

如何才能办到,谢谢!
头像
susbarbatus
帖子: 2966
注册时间: 2010-04-10 16:14
系统: Arch Linux

Re: 【求助】文本抓取

#2

帖子 susbarbatus » 2014-09-29 18:17

代码: 全选

sed -n  '/task task_name*/,/endtask/p' myfile
沉迷将棋中……
halfwolf
帖子: 40
注册时间: 2012-01-28 21:27

Re: 【求助】文本抓取

#3

帖子 halfwolf » 2014-09-29 20:49

susbarbatus 写了:

代码: 全选

sed -n  '/task task_name*/,/endtask/p' myfile
谢谢!
回复