我正在编写一个 Powershell 脚本,将一个大文件拆分为多个文件,每个文件中有两对标签,这些小文件名必须遵循命名约定。
示例abcdef123.xml内容:
<parent>
<child>
<code1><code1>
<text1><text1>
</child>
<child1>
<code2><code2>
<text2><text2>
</child1>
<child>
<code3><code3>
<text3><text3>
</child>
<child1>
<code4><code4>
<text4><text4>
</child1>
<child>
<code5><code5>
<text5><text5>
</child>
<child1>
<code6><code6>
<text6><text6>
</child1>
<child>
<code7><code7>
<text7><text7>
</child>
<child1>
<code8><code8>
<text8><text8>
</child1>
</parent>
Powershell 脚本应将此大文件拆分为多个文件(文件中各有 2 对<child>& <child1>),并具有以下条件,并接受用户输入的文件名约定(所有文件名中的毫秒日期可以保持相同,但变量j应该更改):-
标准:-
- 为每个文件添加 header
<parent>和 tail 。</parent> - 文件名的格式应为
UserinputstringMMDDYYYYHHMMSSMIL_n increment.xml(其中MIL是毫秒,n increment类似于001,002,003, ...) - 没有两个文件应该具有相同的文件名。
示例文件拆分:-
文件 1;stack_10132020134434789_001.xml内容:
<parent>
<child>
<code1><code1>
<text1><text1>
</child>
<child1>
<code2><code2>
<text2><text2>
</child1>
<child>
<code3><code3>
<text3><text3>
</child>
<child1>
<code4><code4>
<text4><text4>
</child1>
</parent>
文件 2;stack_10132020134434791_002.xml内容:
<parent>
<child>
<code5><code5>
<text5><text5>
</child>
<child1>
<code6><code6>
<text6><text6>
</child1>
<child>
<code7><code7>
<text7><text7>
</child>
<child1>
<code8><code8>
<text8><text8>
</child1>
</parent>
我正在尝试的脚本:
csplit -ksf part. src.xml
n=000
#E.g. Enter beginning of file name :
#User entered-> stack
#read userinput
j=n+1
$date= date +%m%d%Y%H%M%S%3N
filename=$userinput$date_$j.xml