Powershell-Word Doc的提取部分

时间:2018-07-16 14:27:36

标签: powershell

使用Powershell,我们成功地基于模式提取了线条

get-content "C:\Search.doc" | 
select-string -pattern "means the aggregate of the Facility" a

但是我们如何从Word文档中提取一个SECTION。参见下面的示例(我们需要在目的部分下的提取点(a)和(b):

3.  PURPOSE
3.1 Purpose
(a) Each Borrower shall apply all amounts borrowed by it under Facility A:
(i) payment to the Vendor of the purchase price for the [xxxx] under the Acquisition Agreement; 
(b) [Each Borrower shall apply all amounts borrowed by it under the Revolving Facility towards the general corporate 

1 个答案:

答案 0 :(得分:0)

您可以使用属性-Context

  

捕获具有匹配项的行之前和之后的指定行数。这使您可以在上下文中查看匹配项。

示例:

$F = Select-String -Path "audit.log" -Pattern "logon failed" -Context 2, 3

第一个命令在Audit.Log文件中搜索短语“登录失败”。它使用Context参数捕获比赛之前的2行和比赛之后的3行。

在您的情况下:

3.  PURPOSE
3.1 Purpose
(a) Each Borrower shall apply all amounts borrowed by it under Facility A:
(i) payment to the Vendor of the purchase price for the [xxxx] under the Acquisition Agreement; 
(b) [Each Borrower shall apply all amounts borrowed by it under the Revolving Facility towards the general corporate 

Select-String -Pattern "under Facility A" -Context 0,2