In the meantime if your files are not too large try a read file task, followed by: {STRING(RowCount|{TASK(PrevTask|StdOut)})}
Edit! Actually forget my answer above, or using get-content which reads the file into memory before operating op it. I need this functionality also, and do some stream editing using the stream reader and writer and tweaked it into a count lines function. It's Fast!
On my 83MB test file, it only took 4.1 seconds to count the lines. The other methods took more than 30 seconds!
Please give this powershell code a try:
#
# GetLineCount(Source, headers, trailers) - Reads a line from a file using streams for memory effiency on large files.
#
Param(
[Parameter(Mandatory=$true)]
[string] $source, # Source file path
[Parameter(Mandatory=$true)]
[ValidateRange(0, [int]::MaxValue)]
[int] $headers, # Header Rows to skip
[Parameter(Mandatory=$true)]
[ValidateRange(0, [int]::MaxValue)]
[int] $trailers # Trailer Rows to skip
)
##
## Read the source file
##
$file = New-Object System.IO.StreamReader($source, [Text.Encoding]::default, $true, 1MB)
while (($line = $file.Readline()) -ne $null) {
$total_lines = $total_lines + 1
}
if ($headers + $trailers) {
$total_lines = $total_lines - ($headers + $trailers)
}
$total_lines
$file.Close()
Note I am no expert and basically know enough powershell to be dangerous so if you see a glaring mistake or room for improvement please let me and future folks that find this know. Thanks!
Edited by user
2019-01-03T14:17:35Z
|
Reason: Not specified