标题: [文本处理] 【已解决】批处理重新编辑多个文本 [打印本页]
作者: JK_m 时间: 2022-5-14 19:16 标题: 【已解决】批处理重新编辑多个文本
本帖最后由 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"
谢谢谢谢
作者: JK_m 时间: 2022-5-15 16:56
本帖最后由 JK_m 于 2022-5-15 17:03 编辑
- @echo off
- setlocal EnableDelayedExpansion
- cd /d "%~dp0"
- for /f "usebackq delims=" %%i in ("1111.txt") do (set txt=%%i)
- for /f "usebackq delims=" %%x in ("1112.txt") do (set txt2=%%x)
- for /f "usebackq delims=" %%z in ("1113.txt") do (set txt3=%%z)
- :loop
- set n=0
- set max=2
- set /a up=max-1
- for %%A in (%txt%) do (
- for %%B in (%txt2%) do (
- for %%C in (%txt3%) do (
- if !n! equ 0 (
- set /p s={%%A,<nul
- ) else if !n! equ %up% (
- set /p s=%%B}<nul
- ) else if !n! equ %max% (
- set /p s= -^> %%C,<nul
- set /a n=-1
- ) else (
- set /p s=%%A,<nul
- )
- set /a n+=1
- )>>3.txt
- )
- )
- echo.
- endlocal
-
- pause
复制代码
回复 4# qixiaobin0715
您能帮忙看看那里出错吗,谢谢
作者: went 时间: 2022-5-15 17:49
test.bat- #&cls&@powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" &pause&exit
- cls
- $arr1 = (Get-Content '1111.txt') -split '\s|\.|,' | Where-Object { $_ -notmatch '^\s*$' }
- $arr2 = (Get-Content '1112.txt') -split '\s|\.|,' | Where-Object { $_ -notmatch '^\s*$' }
- $arr3 = (Get-Content '1113.txt') -split '\s|\.|,' | Where-Object { $_ -notmatch '^\s*$' }
- $line = ''
- 0..$arr1.Count | foreach { $line += '{{{0},{1}}} -> "{2}",' -f $arr1[$_],$arr2[$_],$arr3[$_] }
- $line -replace ',$','' | Out-File '3.txt' -Encoding default
复制代码
作者: JK_m 时间: 2022-5-15 19:00
本帖最后由 JK_m 于 2022-5-15 20:09 编辑
回复 3# went
看不懂的批处理
作者: qixiaobin0715 时间: 2022-5-16 11:05
- @echo off
- setlocal enabledelayedexpansion
- set /p var1=<1111.txt
- set /p var2=<1112.txt
- set /p var3=<1113.txt
- for %%a in (%var1%) do set /a x+=1&set _!x!=%%a
- for %%a in (%var2%) do set /a y+=1&set #!y!=%%a
- for %%a in (%var3%) do (
- set /a n+=1
- if !n! equ 1 (
- set str={!_1!,!#1!}@"%%a"
- ) else (
- if not defined _!n! set _!n!=0
- if not defined #!n! set #!n!=0
- for %%i in (!n!) do set str=!str!,{!_%%i!,!#%%i!}@"%%a"
- )
- )
- set "str=!str:@= -> !"
- echo,!str:.=!>3.txt
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |