@echo off & setlocal enabledelayedexpansion
echo 在处理请耐心等待………………
cd /d D:\招商\RemoteSH\
echo.>汇总.tx&del 汇总.txt 1>nul 2>nul
for /f "tokens=*" %%x in ('dir /b *.txt') do (
set n=0
findstr "☆曾用名" "%%~x" >>汇总.tx
for /f "tokens=1 delims=:" %%a in ('findstr /n "大股东进出" "%%~x"') do set /a x1=%%a-1
for /f "tokens=1 delims=:" %%a in ('findstr /n "所属行业:" "%%~x"') do set /a xx1=%%a-1
for /f "tokens=1 delims=:" %%a in ('findstr /n "证监会行业:" "%%~x"') do set /a xx2=%%a-1
for /f "tokens=1 delims=:" %%a in ('findstr /n /c:"────────────" "%%~x"') do (
if %%a gtr !x1! set /a n+=1
if !n! lss 3 set /a x2=%%a+1
)
set xxx= &call :x !xx1! "%%~x" !xx2!
echo.!xxx!>>汇总.tx
call :xx !x1! "%%~x" !x2!
echo.>>汇总.tx
)
ren 汇总.tx 汇总.txt
start 汇总.txt
exit
:x
for /f "skip=%1 tokens=1,* delims=: " %%a in ('findstr /n .* %2') do (
if %%a lss %3 (set xxx=!xxx!%%b) else (goto :eof)
)
:xx
for /f "skip=%1 tokens=1,* delims=:" %%a in ('findstr /n .* %2') do (
if %%a lss %3 (echo.%%b) else (goto :eof)
)>>汇总.tx
上面代码能将行业的分段落也可以提取,但不知为何部分文本总是不提取如600009这个代码。
@echo off & setlocal enabledelayedexpansion
echo 在处理请耐心等待………………
set "_s= ─────────────────────────────────────"
for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
set "n="
(for /f "usebackq delims=" %%j in ("%%i") do (
set "str=%%j"
if "!str:☆曾用名=!" neq "%%j" echo;%%j
if "!str:所属行业:=!" neq "%%j" echo;%%j
if "!str: 大股东进出 =!" neq "%%j" set "m=0"
if "!m!" equ "0" (
set /a n+=1
set "_!n!=%%j"
if "!str:总 计=!" neq "%%j" set "m=1"
)
)
for /l %%a in (1 1 !n!) do echo !_%%a!
echo %_s%&echo;)>>汇总.txt
)
pause