≡ Menu

How to count number of lines and words in a file using Powershell?

  •  
  •  
  •  

Occasionally you will want to know how many lines are there in a file. In unix world, you can use the nifty ‘wc’ command

wc –l < filename>

In Windows Powershell you can use the built in cmdlet named ‘measure-object’. It is pretty powerful.

For counting lines in a file, use the following command

Get-content <filename> | Measure-Object –Line

For example

If you want to learn more about measure-object,

Help Measure-Object –detailed

Enjoy

 


  •  
  •  
  •  

Comments on this entry are closed.