如何在 PowerShell 中计算行数

如何在 PowerShell 中计算行数

问题描述:

我有一个需要在 PowerShell 中读取的文本文件.

I have a text file that I need to read in PowerShell.

每行的最后一个字符是 Y 或 N.

The last character in each row is either a Y or a N.

我需要查看文件并输出其中有多少个 Y 和 N.

I need to go through the file and output how many Y's and N's are in there.

有什么想法吗?

假设文件名为test.txt"...要获得以 Y 结尾的行数,您可以这样做:

Assuming a file named "test.txt"... To get the number of lines ending in Y, you can do this:

get-content test.txt | select-string Y$ | measure-object -line

要获得以 N 结尾的行数,您可以这样做:

And to get the number of lines ending in N, you can do this:

get-content test.txt | select-string N$ | measure-object -line

希望有所帮助.