如何使用 Windows 批处理文件遍历文本文件中的每一行? [英] How do you loop through each line in a text file using a windows batch file?

查看:26
本文介绍了如何使用 Windows 批处理文件遍历文本文件中的每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 Windows 批处理文件遍历文本文件中的每一行并连续处理每一行文本.

I would like to know how to loop through each line in a text file using a Windows batch file and process each line of text in succession.

推荐答案

我需要将整条生产线作为一个整体进行处理.这是我发现可行的方法.

I needed to process the entire line as a whole. Here is what I found to work.

for /F "tokens=*" %%A in (myfile.txt) do [process] %%A

带星号 (*) 的 tokens 关键字将拉取整行的所有文本.如果您不输入星号,它只会拉出该行的第一个单词.我认为这与空格有关.

The tokens keyword with an asterisk (*) will pull all text for the entire line. If you don't put in the asterisk it will only pull the first word on the line. I assume it has to do with spaces.

用于 TechNet 上的命令

如果你的文件路径中有空格,你需要使用usebackq.例如.

If there are spaces in your file path, you need to use usebackq. For example.

for /F "usebackq tokens=*" %%A in ("my file.txt") do [process] %%A

这篇关于如何使用 Windows 批处理文件遍历文本文件中的每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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