@ECHO OFF
SETLOCAL
::
(
FOR /f "tokens=1*delims=:" %%a IN ('findstr /n /r "." ^<csv1.csv') DO (
FOR /f "tokens=1*delims=:" %%c IN ('findstr /n /r "." ^<csv2.csv') DO (
IF %%a==%%c FOR /f "tokens=1*delims=:" %%e IN ('findstr /n /r "." ^<csv3.csv') DO (
IF %%a==%%e (
FOR /f "tokens=1-4delims=," %%m IN ("%%b") DO (
FOR /f "tokens=1-4delims=," %%r IN ("%%d") DO (
FOR /f "tokens=1-4delims=," %%w IN ("%%f") DO (
ECHO.%%m%%r%%w,%%n%%s%%x,%%o%%t%%y,%%p%%u%%z
)
)
)
)
)
)
)
)>new.csv
应该管用。
它的作用是,
- 对于 file1,FINDSTR “输出”任何包含任何字符 ( ) 的行,该字符 (
/r "."
) 前面是行号和冒号 ( /n
)。此“输出”由 读取FOR /f
并解析为 2 个标记,由冒号分隔(tokens=1*
表示“第一个标记;该行的所有其余部分”),效果是将行号%%a
和该行的其余部分放入,这是从原始.csv
到的行%%b
- FOR EACH LINE 的
csv1
重复 for csv2
,这次将行号放入%%c
, line in%%d
- 仅当行号匹配时,
csv3
使用 in 中的数字%%e
和 in 中的文本重复 for%%f
- 如果最后一个文件中的行号匹配,则解析每个
%%b
,%%d
和%%f
- 中的行文本,这次选择四列,用逗号分隔。该数据出现在%%m
.. %%p
, %%r
.. %%u
, %%w
..中。%%z
我们所要做的就是对接适当的部分并插入逗号。
完毕!
源和测试结果,包括运行时间(5 行)
start:21:45:40.87
end :21:45:41.09
csv1.csv =========
www.domain.com/,www.nwdomain.com/,www.stackdomain.com/,www.example-domain.com/
www.domain.com/,www.nwdomain.com/,www.stackdomain.com/,www.example-domain.com/
www.domain.com/,www.nwdomain.com/,www.stackdomain.com/,www.example-domain.com/
www.domain.com/,www.nwdomain.com/,www.stackdomain.com/,www.example-domain.com/
www.domain.com/,www.nwdomain.com/,www.stackdomain.com/,www.example-domain.com/
csv2.csv =========
about,contact,index,faq
about,contact,index,faq
about,contact,index,faq
about,contact,index,faq
about,contact,index,faq
csv3.csv =========
.html,.html,.html,.html
.html,.html,.html,.html
.html,.html,.html,.html
.html,.html,.html,.html
.html,.html,.html,.html
new.csv =========
www.domain.com/about.html,www.nwdomain.com/contact.html,www.stackdomain.com/index.html,www.example-domain.com/faq.html
www.domain.com/about.html,www.nwdomain.com/contact.html,www.stackdomain.com/index.html,www.example-domain.com/faq.html
www.domain.com/about.html,www.nwdomain.com/contact.html,www.stackdomain.com/index.html,www.example-domain.com/faq.html
www.domain.com/about.html,www.nwdomain.com/contact.html,www.stackdomain.com/index.html,www.example-domain.com/faq.html
www.domain.com/about.html,www.nwdomain.com/contact.html,www.stackdomain.com/index.html,www.example-domain.com/faq.html
=============