How to print a certain line of a file with PowerShell?

后端 未结 6 1140
野趣味
野趣味 2020-12-13 02:49

I don\'t have a decent text editor on this server, but I need to see what\'s causing an error on line 10 of a certain file. I do have PowerShell though...

6条回答
  •  渐次进展
    2020-12-13 03:09

    Just for fun, here some test:

    #Added this for @Graimer's request ;) (not same computer, but one with HD little more #performant...)
    

    measure-command { Get-Content ita\ita.txt -TotalCount 260000 | Select-Object -Last 1 }

    Days              : 0
    Hours             : 0
    
    Minutes           : 0
    Seconds           : 28
    Milliseconds      : 893
    Ticks             : 288932649
    TotalDays         : 0,000334412788194444
    TotalHours        : 0,00802590691666667
    TotalMinutes      : 0,481554415
    TotalSeconds      : 28,8932649
    TotalMilliseconds : 28893,2649
    
    
    > measure-command { (gc "c:\ps\ita\ita.txt")[260000] }
    
    
    Days              : 0
    Hours             : 0
    Minutes           : 0
    Seconds           : 9
    Milliseconds      : 257
    Ticks             : 92572893
    TotalDays         : 0,000107144552083333
    TotalHours        : 0,00257146925
    TotalMinutes      : 0,154288155
    TotalSeconds      : 9,2572893
    TotalMilliseconds : 9257,2893
    
    
    > measure-command { ([System.IO.File]::ReadAllLines("c:\ps\ita\ita.txt"))[260000] }
    
    
    Days              : 0
    Hours             : 0
    Minutes           : 0
    Seconds           : 0
    Milliseconds      : 234
    Ticks             : 2348059
    TotalDays         : 2,71766087962963E-06
    TotalHours        : 6,52238611111111E-05
    TotalMinutes      : 0,00391343166666667
    TotalSeconds      : 0,2348059
    TotalMilliseconds : 234,8059
    
    
    
    > measure-command {get-content .\ita\ita.txt | select -index 260000}
    
    
    Days              : 0
    Hours             : 0
    Minutes           : 0
    Seconds           : 36
    Milliseconds      : 591
    Ticks             : 365912596
    TotalDays         : 0,000423509949074074
    TotalHours        : 0,0101642387777778
    TotalMinutes      : 0,609854326666667
    TotalSeconds      : 36,5912596
    TotalMilliseconds : 36591,2596
    

    the winner is : ([System.IO.File]::ReadAllLines( path ))[index]

提交回复
热议问题