PowerShell get number of lines of big (large) file

Use Get-Content -Read $nLinesAtTime to read your file part by part:

$nlines = 0;

# Read file by 1000 lines at a time
gc $YOURFILE -read 1000 | % { $nlines += $_.Length };
[string]::Format("{0} has {1} lines", $YOURFILE, $nlines)

And here is simple, but slow script to validate work on a small file:

gc $YOURFILE | Measure-Object -Line

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)