如何在 PowerShell 中计算行数 [英] How to count number of rows in PowerShell

查看:75
本文介绍了如何在 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

希望有所帮助.

这篇关于如何在 PowerShell 中计算行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆