2

使用 powershell 获取文件部分内容

 2 years ago
source link: https://www.v2ex.com/t/821017
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

使用 powershell 获取文件部分内容

  oldboy627 · 1 天前 · 759 次点击
彭于晏们,如何使用 powershell 获取 txt 中部分内容,其中红框区域的内容是动态变化的,今天是 4 条,明天可能是 3 条。
9 条回复    2021-12-09 10:36:33 +08:00

kokutou

kokutou      1 天前 via Android

按行读取,
到了 summary 开始记录
到了空行停止。。。
不就行了。。。

skinny

skinny      1 天前

Get-Content -Path MyConmandOutput.txt | Select-Object -First 20 -Skip 4 | Select-String -Pattern '^(Error|Warning) ->\d+'

不过如果是我自己写,我不会为了一行而一行,我会用循环……

skinny

skinny      1 天前

Get-Content -Path MyConmandOutput.txt | Select-Object -First 20 -Skip 4 | Select-String -Pattern '^(Error|Warning) -?\d+'

ladypxy

ladypxy      1 天前

全部读取了然后用正则表达式匹配呗

CallMeReznov

CallMeReznov      23 小时 38 分钟前

如果段落格式是固定的就按照换行符匹配呗

oldboy627

oldboy627      22 小时 43 分钟前

@kokutou 老哥给个例子呗,我也是这么想的,但是不知道怎么写。

oldboy627

oldboy627      22 小时 41 分钟前

@ladypxy 段落格式固定的,红框上下都有空行,能给里例子参考下吗

oldboy627

oldboy627      22 小时 27 分钟前

@ladypxy 正则搞定了,忘记用正则这回事了

oldboy627

oldboy627      22 小时 26 分钟前

@skinny 一个正则匹配^Summary | ^Error | ^Warning 就可以了

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK