在使用文本文件的bash 2标记之间提取线 [英] Extract lines between 2 tokens in a text file using bash

查看:92
本文介绍了在使用文本文件的bash 2标记之间提取线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,它看起来像这样:

i have a text file which looks like this:

random useless text 
<!-- this is token 1 --> 
para1 
para2 
para3 
<!-- this is token 2 --> 
random useless text again

我想提取的令牌(不含当然令牌)之间的文本。我试着用## %%,并以提取的数据,但没有奏效。我想是不是意味着操纵如此大的文本文件。任何建议,我可怎么办呢?也许AWK或sed的?

I want to extract the text in between the tokens (excluding the tokens of course). I tried using ## and %% to extract the data in between but it didn't work. I think it is not meant for manipulating such large text files. Any suggestions how i can do it ? maybe awk or sed ?

推荐答案

您可以提取它,包括与SED的标记。然后用头部和尾部剥夺令牌关闭。

You can extract it, including the tokens with sed. Then use head and tail to strip the tokens off.

... | sed -n "/this is token 1/,/this is token 2/p" | head -n-1 | tail -n+2

这篇关于在使用文本文件的bash 2标记之间提取线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆