counting the number of lines for 100 text files

Welcome Forums General PowerShell Q&A counting the number of lines for 100 text files

Viewing 0 reply threads
  • Author
    Posts
    • #6086
      Participant
      Topics: 1562
      Replies: 0
      Points: 1
      Rank: Member

      by sukans1995 at 2013-05-03 13:21:13

      I would like an easy way to find out for a given path along with filters like "c:\windows|*.txt" as a parameter, the number of lines in each file, along with filename

      Output will be like

      Filename Total lines
      ===========================
      name1.txt 300
      name2.txt 10
      name3.txt 40

      Thanks
      Sukanya

      by ArtB0514 at 2013-05-03 13:50:27

      #requires PowerShell V3.0<br />$FileData = @&#40;&#41;<br />Get-ChildItem c:\Windows -Include *.txt | ForEach-Object {<br />    $FileData += [pscustomobject]@{&#39;FileName&#39;=$_.Name;&#39;Total Lines&#39;=&#40;Get-Content $_.FullName&#41;.Count}<br />}

      or this for any version of PowerShell:
      $FileData=@&#40;&#41;<br />Get-ChildItem C:\Windows -Include *.txt | ForEach-Object {<br />    $FileData += New-Object PSObject -Property @{&#39;FileName&#39;=$_.Name;&#39;Total Lines&#39;=&#40;Get-Content $_.FullName&#41;.Count}<br />}

Viewing 0 reply threads
  • The topic ‘counting the number of lines for 100 text files’ is closed to new replies.