找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 20006|回复: 4

[文本处理] 【已解决】批处理重新编辑多个文本

[复制链接]
发表于 2022-5-14 19:16:15 | 显示全部楼层 |阅读模式
本帖最后由 JK_m 于 2022-5-16 18:25 编辑

点击下载相关文件1111txt1112txt1113txt
;逻辑关系如下有缺失数字用0替代
{1111.txt的第一位数,1112.txt的第一位数} -> "1113.txt的第一位数", {1111.txt的第二位数,1112.txt的第二位数} -> "1113.txt的第二位数" {1111.txt的第三位数,1112.txt的第三位数} -> "1113.txt的第三位数"

4组数据实际效果其余略过。
{343306,347859} -> "1",{345567,344436} -> "1",{339425,342496} -> "1",{336114,342496} -> "-1"
谢谢谢谢
 楼主| 发表于 2022-5-15 16:56:53 | 显示全部楼层
本帖最后由 JK_m 于 2022-5-15 17:03 编辑
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. cd /d "%~dp0"
  4. for /f "usebackq delims=" %%i in ("1111.txt") do (set txt=%%i)
  5. for /f "usebackq delims=" %%x in ("1112.txt") do (set txt2=%%x)
  6. for /f "usebackq delims=" %%z in ("1113.txt") do (set txt3=%%z)
  7. :loop
  8. set n=0
  9. set max=2
  10. set /a up=max-1
  11. for %%A in (%txt%) do (
  12. for %%B in (%txt2%) do (
  13. for %%C in (%txt3%) do (
  14.   if !n! equ 0 (
  15.    set /p s={%%A,<nul
  16.   ) else if !n! equ %up% (
  17.     set /p s=%%B}<nul
  18.   ) else if !n! equ %max% (
  19.     set /p s= -^> %%C,<nul
  20.     set /a n=-1
  21.   ) else (
  22.     set /p s=%%A,<nul
  23.   )
  24.   set /a n+=1
  25.   )>>3.txt
  26. )
  27. )
  28. echo.
  29. endlocal

  30. pause
复制代码
回复 4# qixiaobin0715
您能帮忙看看那里出错吗,谢谢
发表于 2022-5-15 17:49:46 | 显示全部楼层
test.bat
  1. #&cls&@powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" &pause&exit
  2. cls
  3. $arr1 = (Get-Content '1111.txt') -split '\s|\.|,' | Where-Object { $_ -notmatch '^\s*$' }
  4. $arr2 = (Get-Content '1112.txt') -split '\s|\.|,' | Where-Object { $_ -notmatch '^\s*$' }
  5. $arr3 = (Get-Content '1113.txt') -split '\s|\.|,' | Where-Object { $_ -notmatch '^\s*$' }
  6. $line = ''
  7. 0..$arr1.Count | foreach { $line += '{{{0},{1}}} -> "{2}",' -f $arr1[$_],$arr2[$_],$arr3[$_] }
  8. $line -replace ',$','' | Out-File '3.txt' -Encoding default
复制代码

评分

参与人数 1技术 +1 收起 理由
JK_m + 1 谢谢

查看全部评分

 楼主| 发表于 2022-5-15 19:00:33 | 显示全部楼层
本帖最后由 JK_m 于 2022-5-15 20:09 编辑

回复 3# went


    看不懂的批处理
发表于 2022-5-16 11:05:45 | 显示全部楼层
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set /p var1=<1111.txt
  4. set /p var2=<1112.txt
  5. set /p var3=<1113.txt
  6. for %%a in (%var1%) do set /a x+=1&set _!x!=%%a
  7. for %%a in (%var2%) do set /a y+=1&set #!y!=%%a
  8. for %%a in (%var3%) do (
  9.     set /a n+=1
  10.     if !n! equ 1 (
  11.         set str={!_1!,!#1!}@"%%a"
  12.     ) else (
  13.         if not defined _!n! set _!n!=0
  14.         if not defined #!n! set #!n!=0
  15.         for %%i in (!n!) do set str=!str!,{!_%%i!,!#%%i!}@"%%a"
  16.     )
  17. )
  18. set "str=!str:@= -> !"
  19. echo,!str:.=!>3.txt
  20. pause
复制代码

评分

参与人数 1技术 +1 收起 理由
JK_m + 1 谢谢

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-20 00:50 , Processed in 0.019623 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表