[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理怎样在文本文件中追加列?

txt1内容
a
b
c

txt2内容
111
222
333

在txt1中追加txt2的内容,最终变成
a 111
b 222
c 333

哪位大侠能帮忙解决一下

TOP

  1. @echo off & setlocal enabledelayedexpansion
  2. :main
  3.     call:fopen 1.txt one
  4.     call:fopen 2.txt two
  5.     set /A len=fopen_len-1
  6.     (for /L %%i in (0,1,%len%) do echo !one[%%i]! !two[%%i]!)>1.txt
  7. pause
  8. goto:eof
  9. :fopen
  10.     rem %~1 为读取文件名,%~2为储存的变量名
  11.     rem 采用数组的方式储存,不储存换行符
  12.     rem 若无%~2,使用%~n1作为储存的变量名
  13.     set fopen_file=%~1
  14.     if "%~2"=="" ( set "fopen_vale=%~n1" ) else ( set "fopen_vale=%~2" )
  15.     set fopen_len=0
  16.     for /F "tokens=1* delims=:" %%i in ('findstr /n .* %fopen_file%') do (
  17.         set %fopen_vale%[!fopen_len!]=%%j
  18.         set /A fopen_len+=1
  19.     )
  20. goto:eof
复制代码
1

评分人数

TOP

回复 3# wujunkai


这样比较简洁:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. (for /f "delims=" %%i in (1.txt) do (
  4.     set /p str=
  5.     echo,%%i !str!
  6. ))<"2.txt" >"3.txt"
复制代码
1

评分人数

我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

非常好用   谢谢各位大侠

TOP

返回列表