Board logo

标题: [文本处理] [已解决]批处理读取指定txt的下标 [打印本页]

作者: ANSL    时间: 2022-4-14 10:36     标题: [已解决]批处理读取指定txt的下标

读取1.txt的下标以下的内容并输出到2.txt里
1.txt内容:
[config]
AAAA
[DD]
BBBB

读取config下标的内容
读取示例:
AAAA
把结果写入到2.txt
作者: qixiaobin0715    时间: 2022-4-14 11:32

本帖最后由 qixiaobin0715 于 2022-4-14 11:36 编辑

未测试:
  1. @echo off
  2. setlocal enbledelayedexpansion
  3. (for /f "delims=" %%a in (1.txt) do (
  4.     set str=%%a
  5.     if "!str:~,1!"=="[" (
  6.         if "%%a"=="[config]" (
  7.             set n=true
  8.         ) else (
  9.             set n=
  10.         )
  11.     ) else if defined n (
  12.         echo,%%a
  13.     )
  14. ))>2.txt
  15. pause
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2