【发布时间】:2020-10-05 12:34:11
【问题描述】:
我需要在文件中搜索一个词,并在搜索结果中显示一个索引,以便于引用。
bash 中的命令是:
cat <file> | grep 'Table: ' | cat -n
到目前为止我在 Powershell 中所拥有的:
Get-Content <file> | Select-String 'Table: ' | Select-Object -Property LineNumber, Line
不幸的是,我没有意识到LineNumber 给出了文件中的实际行,而不是结果列表中的索引。
如何将 bash 命令转换为等效的 Powershell 命令?
【问题讨论】:
-
我们可以在 bash in powershell 中做到这一点。
cat <file> | grep 'Table: ' | cat -n。get-content <file> | select-string 'Table: ' | (foreach ($line in $(Get-Content -Path test.sh)){$count++; echo "$count $line"})
标签: powershell select-string select-object