开发者

Getting character count for each row in text doc

开发者 https://www.devze.com 2022-12-22 03:58 出处:网络
I am trying to get the character count for each row in a text doc.The contents of my text doc are: 1 15

I am trying to get the character count for each row in a text doc. The contents of my text doc are:

1
15
69
124
300

I've been trying variants of the PS script:

get-content c:\serverlist.txt | foreach-object {measure-object -character}

But the best I can get returned is:

Lines   开发者_JAVA技巧  Words     Characters   Property

-------     --------     --------------   -----------

                                            0

                                            0

                                            0

                                            0

                                            0

Not sure what I'm missing here, but any help would be appreciated!

Thanks!


You have to pipe directly into Measure-Object:

Get-Content c:\serverlist.txt | Measure-Object -Character

Otherwise you'd have to do either

| ForEach-Object { $_ | Measure-Object -Character }

which would be a bit of weird use of the pipeline or

| ForEach-Object { Measure-Object -Character -InputObject $_ }

which would be just about the same as the variant above.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号