Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, April 5, 2011

Powershell foreach-object

If you do

gci | gc | measure-object -character

you get one measurement, on all the files concatenated together.

More useful is

gci | foreach-object { gc $_.name | Measure-Object -character}

which gives a count for each one.

And more useful still is

gci | foreach-object { $_.name + "," + ( gc $_.name | Measure-Object -character ).Characters }

which shows the file names too.

You have to use the parentheses or it doesn't work at all. You have to use .Characters as otherwise you just get the parent Microsoft.PowerShell.Commands.TextMeasureInfo object. I don't understand why that doesn't happen in the second example, but there you go.

Followers

Blog Archive