2015-08-03 32 views
1

我有一個大小爲2.5 GB的日誌文件。有沒有辦法使用Windows命令提示符將此文件分割成更小的文件?如何在Windows中拆分大文本文件?

+0

可能的[複製](http://stackoverflow.com/q/23593556/2152082)(在Windows 7 64位測試) – Stephan

回答

1
Set Arg = WScript.Arguments 
set WshShell = createObject("Wscript.Shell") 
Set Inp = WScript.Stdin 
Set Outp = Wscript.Stdout 
    Set rs = CreateObject("ADODB.Recordset") 
    With rs 
     .Fields.Append "LineNumber", 4 

     .Fields.Append "Txt", 201, 5000 
     .Open 
     LineCount = 0 
     Do Until Inp.AtEndOfStream 
      LineCount = LineCount + 1 
      .AddNew 
      .Fields("LineNumber").value = LineCount 
      .Fields("Txt").value = Inp.readline 
      .UpDate 
     Loop 

     .Sort = "LineNumber ASC" 

     If LCase(Arg(1)) = "t" then 
      If LCase(Arg(2)) = "i" then 
       .filter = "LineNumber < " & LCase(Arg(3)) + 1 
      ElseIf LCase(Arg(2)) = "x" then 
       .filter = "LineNumber > " & LCase(Arg(3)) 
      End If 
     ElseIf LCase(Arg(1)) = "b" then 
      If LCase(Arg(2)) = "i" then 
       .filter = "LineNumber > " & LineCount - LCase(Arg(3)) 
      ElseIf LCase(Arg(2)) = "x" then 
       .filter = "LineNumber < " & LineCount - LCase(Arg(3)) + 1 
      End If 
     End If 

     Do While not .EOF 
      Outp.writeline .Fields("Txt").Value 

      .MoveNext 
     Loop 
    End With 

剪切

filter cut {t|b} {i|x} NumOfLines 

剪切從文件的頂部或底部的行數。

t - top of the file 
b - bottom of the file 
i - include n lines 
x - exclude n lines 

cscript /nologo filter.vbs cut t i 5 < "%systemroot%\win.ini" 

另一種方式它輸出線5001+,適應您的使用。這幾乎不使用內存。

Do Until Inp.AtEndOfStream 
     Count = Count + 1 
     If count > 5000 then 
      OutP.WriteLine Inp.Readline 
     End If 
Loop 
+0

當我嘗試運行腳本我有錯誤,如filter.vbs( 16,13)Microsoft Cursor引擎:內存不足。 – Albin

+0

你有32或64位窗口。如果從64位版本('c:\ windows \ sysnative \ cscript etc')運行64位 - sysnative強制運行System32文件,而不是32位進程的SysWoW64文件。如果32位我們需要另一種技術,這將是特定的而不是通用的。 – bill

+0

我有一個64位的窗口。 – Albin

2

您可以使用命令此任務拆分。 例如該命令輸入到命令提示

split YourLogFile.txt -b 500m 

大小爲每500兆字節創建多個文件。這將需要幾分鐘的時間來處理您的文件大小。您可以將輸出文件(默認名稱爲「xaa」,「xab」,...等)重命名爲* .txt,以在您選擇的編輯器中將其打開。

確保檢查該命令的幫助文件。您還可以按行數拆分日誌文件或更改輸出文件的名稱。

+11

「'split'不被識別爲內部或外部命令,可操作程序或批處理文件。」 - 在Win 7 Ultimate SP1上,64位 –