如何降低HTML标记,从非常大的多行文本文件与使用Perl,awk或者sed内容? [英] How to cut html tag from very large multiline text file with content with use perl, sed or awk?

查看:162
本文介绍了如何降低HTML标记,从非常大的多行文本文件与使用Perl,awk或者sed内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要改造这个文本(删除<数学> *< /数学> ?)使用sed,awk的或Perl:

  {|
| -
|列跨度=2|
:其中,数学>
[\\ underbrace {\\颜色{红} 4,2} _ {4是H. 2},5,1,7] \\ RIGHTARROW
[2,\\ underbrace {\\颜色{OliveGreen} -4,5-} _ {4℃; 5},1,7] \\ RIGHTARROW
[2,4,\\ underbrace {\\颜色{红} 5,1} _ {5是氢。 1},7] \\ RIGHTARROW
[2,4,1,\\ underbrace {\\颜色{OliveGreen} -5,7-} _ {5℃ 7}]
< /数学>
| -
|
:其中,数学>
[\\ underbrace {\\颜色{OliveGreen} -2,4-} _ {2'; 4},1,5,{\\ {色蓝} 7}] \\ RIGHTARROW
[2,\\ underbrace {\\颜色{红} -4,1-} _ {4是H. 1},5,{\\ {色蓝} 7}] \\ RIGHTARROW
并[2,1,\\ underbrace {\\颜色{OliveGreen} -4,5-} _ {4℃; 5},{\\ {色蓝} 7}]
< /数学>
:其中,数学>
[\\ underbrace {\\ {色红}} 2,1 _ {2 - ; 1},4,{\\ {色蓝} 5},{\\ {色蓝} 7}] \\ RIGHTARROW
[1,\\ underbrace {\\颜色{OliveGreen} -2,4-} _ {2'; 4},{\\ {色蓝} 5},{\\ {色蓝} 7}]
< /数学>
:其中,数学>
[\\ underbrace {\\ {颜色} OliveGreen 1,2} _ {1< 2},{\\ {色蓝} 4},{\\ {色蓝} 5},{\\ {色蓝} 7}]
< /数学>
|}

到这样的文本(请原谅我,如果我删除太多 - 我应该删除<数学> *< /数学> ?):

  {|
| -
|列跨度=2|

| -
|



|}

我读到第20页和测试脚本,10,但没有很好的效果。最好的我做的是:

 猫污垢math.txt | awk的'/<数学> / {切= 1;打印;} /< \\ /数学>!/ {切= 0}腰斩

不管它不能正常工作,因为左派<数学>< /数学> 这是不坏,但我不知道awk来进一步提高它。

解决方案

如果所有的数据都这么好听格式化为你的榜样,那么你的解决方案是非常接近的。我修改了它只是稍微

在AWK:

 子(/<数学方式> * /,){打印;切= 1}
/< \\ /数学> / {切= 0;下一个}
!切

I want to transform this text (remove <math>.*?</math>) with sed, awk or perl:

{|
|-
| colspan="2"|
: <math>
[\underbrace{\color{Red}4,2}_{4 > 2},5,1,7] \rightarrow
[2,\underbrace{\color{OliveGreen}4,5}_{4 < 5},1,7] \rightarrow
[2,4,\underbrace{\color{Red}5,1}_{5 > 1},7] \rightarrow
[2,4,1,\underbrace{\color{OliveGreen}5,7}_{5 < 7}]
</math>
|-
|
: <math>
[\underbrace{\color{OliveGreen}2,4}_{2 < 4},1,5,{\color{Blue}7}] \rightarrow
[2,\underbrace{\color{Red}4,1}_{4 > 1},5,{\color{Blue}7}] \rightarrow
[2,1,\underbrace{\color{OliveGreen}4,5}_{4 < 5},{\color{Blue}7}]
</math>
: <math>
[\underbrace{\color{Red}2,1}_{2 > 1},4,{\color{Blue}5},{\color{Blue}7}] \rightarrow
[1,\underbrace{\color{OliveGreen}2,4}_{2 < 4},{\color{Blue}5},{\color{Blue}7}]
</math>
: <math>
[\underbrace{\color{OliveGreen}1,2}_{1 < 2},{\color{Blue}4},{\color{Blue}5},{\color{Blue}7}]
</math>
|}

Into such text (please forgive me if I remove too much - I should remove <math>.*?</math>):

{|
|-
| colspan="2"|
: 
|-
|
: 
: 
: 
|}

I read about 20 page and tested 10 scripts but without good results. The best what I do is:

cat dirt-math.txt | awk '/<math>/{cut=1; print;}/<\/math>/{cut=0}!cut'

Whatever it not works correctly since lefts <math></math> it is not bad but I do not know awk to improve it more.

解决方案

If all data is so nicely formatted as in your example, then your solution is very close. I modified it only slightly

in AWK:

sub(/<math>.*/, "") {print; cut=1}
/<\/math>/          {cut=0; next}
!cut

这篇关于如何降低HTML标记,从非常大的多行文本文件与使用Perl,awk或者sed内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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