China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 16:03
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to insert a specific line of content into the third line of all txt texts in a folder View 2,105 Replies 1
Original Poster Posted 2021-06-29 23:18 ·  中国 陕西 西安 移动
新手上路
Credits 2
Posts 2
Joined 2021-06-29 01:11
4-year member
UID 184474
Gender Male
Status Offline
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
Floor 2 Posted 2021-07-04 00:59 ·  中国 陕西 移动
新手上路
Credits 2
Posts 2
Joined 2021-06-29 01:11
4-year member
UID 184474
Gender Male
Status Offline
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
Forum Jump: