I want to add some text to 100 lines of a notepad. For example I have a file called d.txt and want to add test to all 100 lines of d.txt.
The output should be
test line 1
test line 2
test line 3I am aware of dos command and batch utility but not sure as how do I do it.
Some one please help me.
@echo off
set local
REM looping through d.txt evaluating it line by line
for /f "tokens=*" %%a in (d.txt) do (
REM writing to d_new.txt the string "test", the value of the current line from d.txt, and the string "similar_kind_of_text"
echo test %%a similar_kind_of_text >> d_new.txt
)
REM after loop is finished, deleting original d.txt
del /q d.txt
REM renaming d_new.txt to d.txt
ren d_new.txt d.txt
endlocal
@echo off set incr=0
:write
set /a incr=%incr%+1
if %incr% geq 101 goto end
echo test line %incr% >> d.txt
goto write
:end
Thanks a lot for the reply. But since I am not much into programming I am not sure as what word will this code it will insert into the test file and if I need to insert some other text at the end of line how do I do that. Expecting some reply and thanks a lot for hte solutions.
Also how do I run this code. Should I make a bat file or how do I run this code.
Make a batch file.
yourtexthere.bat
Thanks for the replies. I am able to run using the batch file. But I think I made a mistake in putting my question. Hence trying to reframe the question properly. I want to insert some text ahead of a text file. The text file is having some data in a columnar format for e.x. 100
400
500
600
700
900The above nos are just an example. It could be even data in form of words such as hi
how
hello
Hence I want the data to appear astest 100
test 400
test 500
test 600
test 700
test 900testhi
test how
test helloSo kindly help me as how do I this.
So the text file already has a value on each line. That means we don't need to increment a number or anything like that, we just need to add "test" to the start of each line. @echo off
set local
for /f "tokens=*" %%a in (d.txt) do (
echo test %%a >> d_new.txt
)
del /q d.txt
ren d_new.txt d.txt
endlocal
Thanks a ton. Its working. Now I have small problem or query. I need to some similar kind of text at the end of each line. So how do I add that text. If possible try to add the code in the above answer only so I have to work with just 1 batch file and also guide me as what each code is doing, so I can know accordingly.
@echo off
set local
REM looping through d.txt evaluating it line by line
for /f "tokens=*" %%a in (d.txt) do (
REM writing to d_new.txt the string "test", the value of the current line from d.txt, and the string "similar_kind_of_text"
echo test %%a similar_kind_of_text >> d_new.txt
)
REM after loop is finished, deleting original d.txt
del /q d.txt
REM renaming d_new.txt to d.txt
ren d_new.txt d.txt
endlocal
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |