PowerShell get number of lines of big (large) file

前端 未结 8 1145
小鲜肉
小鲜肉 2020-12-23 16:35

One of the ways to get number of lines from a file is this method in PowerShell:

PS C:\\Users\\Pranav\\Desktop\\PS_Test_Scripts> $a=Get-Content .\\sub.ps1         


        
相关标签:
8条回答
  • 2020-12-23 17:21

    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
    
    0 讨论(0)
  • 2020-12-23 17:27

    MS DOS command FIND : $fileName = 'C:\dirname\filename.txt'
    CMD /C ('find /v /c "" "' + $fileName + '"')
    Other variations on the find command can be found on the docs.

    0 讨论(0)
提交回复
热议问题