使用Findstr /N
到編號的文件
> findstr /N ".*" test.txt
1:0181830207709014000015576526S00000140000014000001242017
2:0052500056661095000015576527S00000950000095000001242017
3:0157020294103030000015576528S00000300000030000001242017
4:2397870060994031500015576529S00000315000031500001242017
5:2466260219154015000015576530S00000150000015000001242017
而且一個For /f
環的線路到瓦爾%%A
的號碼解析輸出,分裂在結腸和行內容爲%%B
。如果號碼是2
請插入額外的行。
@Echo off
Set "File=Test.txt"
Set "NewFile=TestNew.txt"
(
For /f "Tokens=1*Delims=:" %%A in (
'Findstr /N ".*" "%File%"'
) Do If %%A Equ 2 (
Echo:insert me a new line before
Echo:%%B
Echo:insert me a new line below
) Else (
Echo:%%B
)
) >"%NewFile%"
EDIT改變了邏輯後續的讀者。示例輸出:
> type TestNew.txt
0181830207709014000015576526S00000140000014000001242017
insert me a new line before
0052500056661095000015576527S00000950000095000001242017
insert me a new line below
0157020294103030000015576528S00000300000030000001242017
2397870060994031500015576529S00000315000031500001242017
2466260219154015000015576530S00000150000015000001242017
您首先搜索類似的問題和答案對或提供您現有的代碼。解釋你如何運行該代碼,它做了什麼,你期望發生什麼以及你需要什麼幫助。 _(請理解這不是免費的寫作服務)_ – Compo