中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-15 03:12
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » How to insert a specific line of content into the third line of all txt texts in a folder
Printable Version  2,442 / 1
Floor1 2906879113 Posted 2021-06-29 23:18
新手上路 Posts 2 Credits 2
Ask the expert:
How to insert a specific data content in the third line of all txt texts in the folder:
For example, the file names are as follows:
aaaa.txt
eeSeeee.txt
ffffffff.txt
88X888.txt
66666.txt
Insert after the second line in each file: (564789,21693,45655555).
After insertion, the text becomes like this:
123
245XC
(564789,21693,45655555)
34545
44545
5454
64545
Floor2 2906879113 Posted 2021-07-04 00:59
新手上路 Posts 2 Credits 2
Through several days of online shopping batch processing materials, and then self-study, practice, achieve the goal. It's really amazing.

Now release the code, hope friends to correct. 2021-07-05

How to insert a specific data content into the third line of all txt texts in the folder:
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b *.txt') do (
for /f "usebackq delims=" %%b in ("%%a") do (
set/a n+=1

if !n! lss 0 ( exit
) else if !n! equ 3 (
echo ^(增加行文字lhc^)>>new_%%a
echo %%b>>new_%%a
) else (
echo %%b>>new_%%a
)

)
set/a n=0
)

@pause
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023