4

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     Words     Characters   Property
-------     --------     --------------   -----------
                                            0
                                            0
                                            0
                                            0
                                            0

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

Thanks!

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Both the second and third choices give me what I'm looking for. Just didn't know the context. Thanks Johannes!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.