Getting the number of characters for each line in a text document

I am trying to get the number of characters for each line in a text document. The contents of my text document:

1 15 69 124 300 

I tried the PS script options:

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

But the best I can get is:

Lines Characters
Real Estate ------- -------- -------------- ----------
0
0
0
0
0

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

Thanks!

+4
source share
1 answer

You need to connect directly to Measure-Object :

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

Otherwise you will have to do either

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

which will be a little weird using a conveyor belt or

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

which will be about the same as the option above.

+6
source

Source: https://habr.com/ru/post/1302901/


All Articles