如何判断文本文件里是否含有特定字符串
发表于 : 2008-03-14 18:54
又要求助各位了, 有一个文本文件a.txt, 有一些XML标签和其它文本的混合:
我要对这个文本进行处理, 不断的删除XML标签和它中间的内容, 一直到全部删除完为止. XML标签有一定的规律, <T数字>, 用正则表达式查找就行了.
请问要用什么命令来实现这个判断,grep, sed? 用最简单的方法来实现就可以了,不用获取标签之间的内容,只要判断有没有标签就行了.
谢谢.
Thanks for your help, actually the problem is not so difficult as you guys thought. My poor expression misleaded. Below is the solution I used(There is no Chinese input available in Lab, so I just post in English.):
----------------------------------solution begin----------------------------------------------------------------
代码: 全选
title: test
<T1>
123
</T1>
Tag for T1 is 123
<T2>
321
</T2>
请问要用什么命令来实现这个判断,grep, sed? 用最简单的方法来实现就可以了,不用获取标签之间的内容,只要判断有没有标签就行了.
谢谢.
Thanks for your help, actually the problem is not so difficult as you guys thought. My poor expression misleaded. Below is the solution I used(There is no Chinese input available in Lab, so I just post in English.):
----------------------------------solution begin----------------------------------------------------------------
代码: 全选
#calcuate how many tags in the file
tagsNumber=$(egrep -c '/*<T' source.txt)
#do if there is tag in the file
while [ $tagsNumer -gt 0 ]; do
...... ....
# I will remove one tag(in pair) each time, so re-calculate it
tagsNumber=$(egrep -c '/*<T' source.txt)
done #end of while loop