我正在尝试从文本文件中删除“已删除的变量”。 要删除以“#Begin Removed Variable”开始并以“#End Removed Variable”结束的数据。
模式如下:
# Begin Test Case
File = ..\SVN\XXX.CPP
Procedure = XX
Procedure Number = 1
Member Of = 1
Creation Date = Jun XX 2019 14:36:44
Description = This test is to verify
# Begin Variable
Name = YY
Decl_type = uchar*
Usage = N
TBrun Analysis = Compare
Value = YY
# End Variable
# Begin Removed Variable
Name = b_side_fired
Decl_type = gun_class
Usage = M
# End Removed Variable
# End Test Case
我是新手,所以我无法判断和继续。
输出如下所示。删除所有“#Begin Removed variables ....”的内容,并结束于“ End Removed variables”及其在文件中的所有出现。 例如:如下所示,所有已删除的变量都将被删除。
# Begin Test Case
File = ..\SVN\XXX.CPP
Procedure = XX
Procedure Number = 1
Member Of = 1
Creation Date = Jun XX 2019 14:36:44
Description = This test is to verify
# Begin Variable
Name = YY
Decl_type = uchar*
Usage = N
TBrun Analysis = Compare
Value = YY
# End Variable
# End Test Case
答案 0 :(得分:1)
单线可就地编辑文件:
perl -ni -e 'print unless /# Begin Removed Variable/ .. /# End Removed Variable/' yourfile.txt
基本上,它仅打印行,除非它们位于那些已删除的块之一中。 More information关于标量..
的使用。
用于比较的非原位awk版本({,
就像perl中的..
):
awk '/# Begin Removed Variable/, /# End Removed Variable/ { next } 1' yourfile.txt
并完成:
sed '/# Begin Removed Variable/, /# End Removed Variable/ d' yourfile.txt
某些版本的sed支持-i
进行Perl等就地编辑。
答案 1 :(得分:0)
以下是如何完成此操作的示例:
SELECT DISTINCT G.CITY FROM TBLGEOMARKET G,TBLGEOMARKET GM
WHERE GM.ID = G.PARENTID AND GM.PARENTID = 15;