https://www.yuque.com/lengyuezuixue/warh99/wsx190

    1. @echo off&setlocal enabledelayedexpansion
    2. rem 生成文件
    3. tasklist | findstr "Console">bat.txt
    4. rem 文件不存在,就结束
    5. if not exist bat.txt goto end
    6. rem 读取文件第一列
    7. rem type是显示文件内容的命令
    8. for /f %%a in ('type bat.txt') do echo %%a
    9. pause
    10. rem 读取文件第二列
    11. for /f "tokens=2" %%b in (bat.txt) do (
    12. echo %%b
    13. )
    14. pause
    15. rem 读取所有列
    16. for /f "tokens=*" %%c in (bat.txt) do (
    17. echo %%c
    18. )
    19. pause
    20. rem 读取文件
    21. rem /I 字符串比较不分大小写
    22. for /f "tokens=1" %%d in (bat.txt) do (
    23. if /I "%%d" equ "cmd.exe" (
    24. echo %%d
    25. )
    26. )
    27. pause
    28. rem 读取文件
    29. for /f "tokens=*" %%e in ('findstr /b /i "cmd.exe" bat.txt') do (
    30. echo %%e
    31. )
    32. pause
    33. rem 读取文件
    34. for /f "tokens=*" %%f in (bat.txt) do (
    35. echo %%f | find "cmd.exe"
    36. echo %%f | find "cmd.exe">nul&&echo "cmd"
    37. )
    38. :end
    39. pause