批处理脚本 - 读一行一行 [英] batch script - read line by line

查看:150
本文介绍了批处理脚本 - 读一行一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有
我有线路和管道,我需要读取日志文件中,一行行至下一个循环

hello all i have a log file which i need to read in, line by line and pipe the line to a next loop

首先,我用grep日志文件中一个单独的文件中的主字(如错误) - 以保持它小。现在我需要采取单独的文件,并在一行行读它 - 每行需要去另一个循环(这些循环用grep我的日志,并以块为单位划分的话),但我坚持在这里

first i grep the logfile for the "main" word (like "error") in a seperate file - to keep it small. now i need to take the seperate file and read it in line by line - each line needs to go to another loop (in these loop i grep the logs and divide it in blocks) but i stuck here

日志看起来像

XX.XX.XX.XX - - http://www.blub.com/something/id=?searchword-yes-no200 - something_else
用FOR / F循环我只是获取IP,而不是整条生产线。

xx.xx.xx.xx - - "http://www.blub.com/something/id=?searchword-yes-no" 200 - "something_else" with a for /f loop i just get the ip instead of the complete line.

我怎么能管/写/缓冲整条生产线 - 并不重要是什么,每行写。
感谢你们
快乐的圣诞节所有

how i can pipe/write/buffer the whole line - doesnt matter what is written per line. thank you guys happy christmas all

推荐答案

试试这个:

@echo off
for /f "tokens=*" %%a in (input.txt) do (
  echo line=%%a
)
pause

因为定情= * 一切都捕获到%A

修改
回复您的留言,你就必须做到这一点是这样的:

edit: to reply to your comment, you would have to do that this way:

@echo off
for /f "tokens=*" %%a in (input.txt) do call :processline %%a

pause
goto :eof

:processline
echo line=%*

goto :eof

:eof

由于空间的,你不能使用%1 ,因为这将只包含一部分,直到第一个空格。而且由于行包含引号,你也可以不使用:ProcessLine从%%一个结合%〜1 。所以,你需要使用%* 其中获得%1%2%3 ... ,所以整行。

Because of the spaces, you can't use %1, because that would only contain the part until the first space. And because the line contains quotes, you can also not use :processline "%%a" in combination with %~1. So you need to use %* which gets %1 %2 %3 ..., so the whole line.

这篇关于批处理脚本 - 读一行一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆