Link to home
Start Free TrialLog in
Avatar of Mugiwara Yanko
Mugiwara YankoFlag for Japan

asked on

PowerShell script to get the total records count from a .dsv files

Need help with a PowerShell script to get the total count of records (excluding the header) for the 14 .dsv files specified and print them in the output with the file name.


Sample expectation : 


pick files from a folder : 

file1.dsv,

file2.dsv,

file3.dsv,

.

..

...

file14.dsv 



Now get the total counts of records(no of rows without header) in each file excluding the header and print them on output like below.



output : 


file1.dsv | 160

file2.dsv | 130

file3.dsv | 155

.

..

...

file14.dsv | 2500



ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dfke
dfke

Hi,

$folderPath = "C:\YourFolderPath"
Get-ChildItem -Path $folderPath -Filter *.dsv | ForEach-Object {
    $file = $_.FullName
    $lineCount = (Get-Content $file | Measure-Object -Line).Lines - 1
    Write-Host "$($_.Name) | $lineCount"
}

Open in new window


Cheers