@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
應該工作。
它的作用是,
- 對於文件1,FINDSTR「輸出」,其中包含由行號和冒號(
/n
)之前的任何字符(/r "."
)的任何行。這個「輸出」被FOR /f
讀取並且被解析成由冒號分隔的2個標記(tokens=1*
表示'第一個標記;該行的所有其餘部分'),並且效果是將行號放入%%a
中,其餘的行了,這是從原來的.csv
行成%%b
- FOR爲
csv2
csv1
重複的每一行,此時放置行號%%c
,線%%d
- 的只有在訂單號碼相符,重複
csv3
與%%e
中的數字和%%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
=============
如果我可以運行這個自動 – 2013-03-23 11:15:27