1.

Solve : adding to a file?

Answer»

how do i add a variable to the start of every line in a fileYou would probably have to rewrite the file. To add a colon as the first character in each line of a TEXT file, you can set the variable to the colon and process the file like:
Code: [Select]@echo off
set PREFIX=:
set Infile=test.txt
set Outfile=new.txt

if exist %Outfile% del %Outfile%
for /f "delims=" %%a in (%Infile%) do echo %Prefix%%%a >>%Outfile%
If you WANT to replace the original file with the modified VERSION, you would add:
Code: [Select]del %Infile%
ren %Outfile% %Infile%If either INFILE or OUTFILE have spaces in them, be sure to surround them in double-quotes.Quote

how do i add a variable to the start of every line in a file

You should already know how to loop over a file using for loop.
so just set the variable, eg set var=somevariable
then while you are looping over the file, do an echo %var%%%i

this will add the variable in front of the line.OK THINK you i did not think a for loop would work i thought that it would just add to the first line


Discussion

No Comment Found