首页 > 解决方案 > 从 10GB Informatica 会话日志中读取前 10 行的 Windows 批处理脚本

问题描述

Windows 批处理控制台中的 for 循环在处理 10 GB 的大文件时挂起并且不起作用,但适用于小于 1 GB 的较小文件。例如

FOR /F "delims=]" %%A IN (dummy.txt) DO ( 
...code...
)

我需要一个批处理脚本,它可以有效地从 10 gb Informatica 会话日志文件中读取前 10 行代码。有没有办法使用批处理编程来读取大文件?

标签: windowsbatch-file

解决方案


尝试这个:

@echo off
setlocal EnableDelayedExpansion

rem Read first 10 lines
(for /L %%i in (1,1,10) do set /P "line[%%i]=") < dummy.txt

rem Process them
for /L %%i in (1,1,10) do (
   echo Line %%i- !line[%%i]!
   FOR /F "delims=]" %%A IN ("!line[%%i]!") DO (
      ...code...
   )
)

PS - 我敢打赌这种方法比 PowerShell 运行得快得多!;)


推荐阅读