請問各位大神們,小弟目前電腦有上百個文字檔內容格式如下,
檔名:0000_MMDDYYYY.txt;1111_MMDDYYYY.txt;2222_MMDDYYYY.txt.............
內容大致上如下,
number1 = XXXXXX
number2 = ZZZZZZ
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
...............................
想把這些文字檔案的內容合成為一個文字檔,但合成後的內容不要把number1 = XXXXXX和number2 = ZZZZZZ寫入,且格式想變為
0000_MMDDYYYY,ZZZZZZ,PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
0000_MMDDYYYY,ZZZZZZ,OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
1111_MMDDYYYY,ZZZZZZ,PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
1111_MMDDYYYY,ZZZZZZ,OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
請問使用DOS批次檔如何達成呢?
有試著寫了一個批次檔,但會變成
0000_MMDDYYYY,number1 = XXXXXX
0000_MMDDYYYY,number2 = ZZZZZZ
0000_MMDDYYYY,PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
0000_MMDDYYYY,OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
1111_MMDDYYYY,number1 = XXXXXX
1111_MMDDYYYY,number2 = ZZZZZZ
1111_MMDDYYYY,PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
1111_MMDDYYYY,OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
請參考
注意執行時會刪除前次儲存的記錄檔(integrate.Log)
@ECHO OFF
Set Integrate=integrate.Log
Del /Q %integrate% 1 2>Nul
For /f "Delims=: Tokens=1-4" %%i In ('Findstr /N /R /C:"^number:\>" *.txt') Do Call :Write %%j %%i %%l
Exit /b
:Write
For /f "Skip=%1 Delims=*" %%o In ('Findstr . "%2"') Do Echo %%~ni,%3,%%o >>%Integrate%
麻煩描述更清楚一點
檔案1檔名為 computer1_01162019.txt
內文如下:
machine: computer1
number: 變數1
檔案2檔名為 computer2_01162019.txt
內文如下:
machine: computer2
number: 變數2
想透過批次檔將檔案1和檔案2的內容寫到同一個文字檔,
computer1_01162019, 變數1, 000001 aaa 11111 11111 11111
computer1_01162019, 變數1, 000002 bbb 22222 22222 22222
.
computer1_01162019, 變數1, 000026 zzz 26262 26262 26262
computer2_01162019, 變數2, 000001 aaa 11111 11111 11111
computer2_01162019, 變數2, 000002 bbb 22222 22222 22222
.
computer2_01162019, 變數2, 000026 zzz 26262 26262 26262