BAT读取文件
程序员文章站
2022-04-08 17:09:47
...
@echo off&setlocal enabledelayedexpansion
rem 生成文件
tasklist | findstr "Console">bat.txt
rem 文件不存在,就结束
if not exist bat.txt goto end
rem 读取文件第一列
rem type是显示文件内容的命令
for /f %%a in ('type bat.txt') do echo %%a
pause
rem 读取文件第二列
for /f "tokens=2" %%b in (bat.txt) do (
echo %%b
)
pause
rem 读取所有列
for /f "tokens=*" %%c in (bat.txt) do (
echo %%c
)
pause
rem 读取文件
rem /I 字符串比较不分大小写
for /f "tokens=1" %%d in (bat.txt) do (
if /I "%%d" equ "cmd.exe" (
echo %%d
)
)
pause
rem 读取文件
for /f "tokens=*" %%e in ('findstr /b /i "cmd.exe" bat.txt') do (
echo %%e
)
pause
rem 读取文件
for /f "tokens=*" %%f in (bat.txt) do (
echo %%f | find "cmd.exe"
echo %%f | find "cmd.exe">nul&&echo "cmd"
)
:end
pause
下一篇: poi解析excel简单小例子