【发布时间】:2020-09-25 06:42:16
【问题描述】:
Powershell cmd 的“上下文行控制”设置是什么:findstr 或什么是替代 Powershell cmd,它可以让我在某些输出中找到字符串并方便我打印周围的行?
在 GNU/Linux 上我会这样做:grep -A 5 -B 5 somestring file.txt
下面的命令搜索字符串“four”,但要求 grep 在找到的行上方显示 1 行,在找到的包含字符串的行下方显示 2 行。
$ grep -A 2 -B 1 four tmp.text
three
four
five
six
$ cat tmp.text
one
two
three
four
five
six
seven
谢谢
【问题讨论】:
-
我添加了一个示例来说明我在寻找什么。
-
看看Select-String。您应该阅读完整的帮助,包括示例以了解如何使用它。
-
我喜欢你在他发布答案后立即回答的方式。
标签: powershell cmd command full-text-search command-line-arguments