批处理:判断从文件读取的行中是否存在子字符串
我对批次是全新的。 我的目的是编写一个批处理,从文件中读取每一行,并根据读取的行执行一些不同的任务。这是一些示例
@echo off
setlocal enableextensions enabledelayedexpansion
for /f "usebackq delims=" %%a in (test.txt) do (
echo %%a
*if %%a contains abc do (other tasks)*
)
此外,我可以批量检测“换行符”吗? 如果 test.txt 看起来像:
123
345
abckdla
abd
abd
abc
test
当 for 循环位于 test.txt 的 row4 和 row8 时,我可以打印“这是一个新行”吗?
非常感谢您的宝贵时间。
I am brand new to batch.
My intention is writing a batch that read every line from a file, and depends on the line read in do some different tasks. Here is some sample
@echo off
setlocal enableextensions enabledelayedexpansion
for /f "usebackq delims=" %%a in (test.txt) do (
echo %%a
*if %%a contains abc do (other tasks)*
)
In addition, can I detect a "newline" in batch??
if the test.txt looks like:
123
345
abckdla
abd
abd
abc
test
can I print "this is a new line" when the for loop is at row4 and row8 of test.txt??
Great thanks to your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的帖子中有两个问题
1.- 检查变量是否包含子字符串。
尝试一下,
请参阅
HELP SET
以获取更多详细信息。2.- FOR 命令跳过空行。尝试
HELP FOR
并阅读“跳过空白行”。除非绝对必要,否则我会尽量避免涉及例如
TYPE
和FIND
的复杂解决方案。There are two questions in your post
1.- Checking if a variable contains a substring.
try this
see
HELP SET
for more detailed information.2.- the FOR command skips blank lines. Try
HELP FOR
and read "Blank lines are skipped".There are convoluted solutions involving for example
TYPE
andFIND
I would try to avoid unless strictly necessary.