批处理脚本中提取两个指定行之间线 [英] batch script to extract lines between two specified lines
问题描述
我有一个文本文件,并想通过提取Windows批处理脚本两个指定行之间的所有行。
1号线:FILE_FORMAT = ADS
2号线:VERSION = 1.0
LINEX:'父|子|值isPrimary | * 的*** (行始于和长)
LineY:PropertyArray =成本中心(!该行开头)
LineZ。
我想所有LINEX和LineY并输出之间的界线提取到另一个文件。
下面code正确地找到了起跑线上。但它只是删除,我想停止脚本和输出文件的其余部分的线(线Y)。
输出从线X到线Z没有Y线。
@for / F令牌= 1 delims = []%%一中(查找/ N'家长|孩子^< D:\\ DEV \\测试\\ Cost_Center.txt')做@(
更多+ %%一个D:|!PropertyArray =成本中心\\ DEV \\测试\\ Cost_Center.txt找到/ V || GOTO:EOF)> D:\\ DEV \\测试\\ Cost_Center_Out.txt
您可以做到这一点的sed的Windows:
sed的/父母|儿童|值isPrimary | /,/ PropertyArray =成本中心/ D!文件1>文件2
I have a text file and would like to extract all the lines between two specified lines using windows batch scripting.
Line1: !FILE_FORMAT=ADS
Line2: !VERSION=1.0
.
.
LineX: 'Parent|Child|IsPrimary|**** (the line starts with ' and is long)
.
.
LineY: !PropertyArray=Cost Center (The lines starts with !)
.
.
LineZ.
I want to extract all the lines between LineX and LineY and output it to another file.
The below code finds the starting line correctly. But it just deletes the line(Line Y) where I want the stop the script and outputs the rest of the file.
The output is from Line X to Line Z without Line Y.
@for /f "tokens=1 delims=[]" %%a in ('find /n "'Parent|Child"^<D:\DEV\Test\Cost_Center.txt') do @(
more +%%a D:\DEV\Test\Cost_Center.txt |find /v "!PropertyArray=Cost Center" || goto :eof)>D:\DEV\Test\Cost_Center_Out.txt
you can do this with sed for Windows:
sed "/'Parent|Child|IsPrimary|/,/!PropertyArray=Cost Center/!d" file1 > file2
这篇关于批处理脚本中提取两个指定行之间线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!