@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
動作するはずです。
それがすることは、
/r "."file1 の場合、FINDSTR は、任意の文字 ( ) の前に行番号とコロン ( )を含む行を「出力」します/n。この「出力」は によって読み取られFOR /f、コロンで区切られた 2 つのトークンに解析されます ( tokens=1*「最初のトークン; 行の残りのすべて」を意味します)。その結果、行番号と行の残りの部分が挿入%%aされます。 、これは元から.csvへの行です%%b
- FOR EACH LINE
csv1for Repeat for csv2、今回は行番号を に%%c、行を%%d
- 行番号が一致する場合のみ
csv3、番号%%eを入力してテキストを入力して繰り返します%%f
- この最後のファイルの行番号が一致する場合は、それぞれの行テキストを解析し、今回
%%bはコンマで区切られた 4 つの列を選択します。このデータは.. 、.. 、..で表示されます。あとは、適切な部分を突き合わせてコンマを挿入するだけです。%%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
=============