powershell - Powershell - 从 Word Doc 中提取部分
问题描述
使用Powershell,我们成功提取了基于pattern的线条
get-content "C:\Search.doc" |
select-string -pattern "means the aggregate of the Facility" a
但是我们如何从 word doc 中提取一个 SECTION。请参见下面的示例(我们需要提取点 (a) 和 (b) 位于 PURPOSE 部分下:
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
解决方案
您可以使用该属性-Context
:
在匹配的行之前和之后捕获指定数量的行。这允许您在上下文中查看匹配。
例子:
$F = Select-String -Path "audit.log" -Pattern "logon failed" -Context 2, 3
第一个命令在 Audit.Log 文件中搜索短语“logon failed”。它使用 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
推荐阅读
- asp.net-core - 无法使用 glyphicon 图像网络核心
- javascript - 当我尝试向我的网站添加反应时没有任何反应,看起来浏览器没有检测到文件
- java - JAVA.UTIL.NoSuchElementException 错误(基于情况)
- ios - 无法更改 MDCTextField i 的 UI
- javascript - 循环遍历对象数组并将其存储在表中[JS]
- c - 如何在一行中增加或减少 C 函数调用中的指针参数值?
- stm32 - STM32调试问题
- ssl - 如何从 CherryPy 处理程序获取 SSL 客户端证书信息?
- node.js - 从集合中检索所有文档后如何很好地显示字段内容
- javascript - 从参考重新创建混合二等分和错误位置算法