Add command to lines in a text file

Dell / Dimension 4600i...
January 16, 2011 at 13:05:35
Specs: Microsoft Windows XP Home Edition, 2.793 GHz / 1534 MB
I have a file called myfile.txt
It contains 100 lines of text
Example:
drivegrabber
duck
EasyBoot
hexedit
Linksys Driver
Linksys Driver2
loadset
mysite
New Folder
End of example.....................

Using the below does the following

@echo off
setlocal
set addtext=copy 
for /f "delims=" %%a in (myfile.txt) do (echo/|set /p =%%a%addtext% & echo\ & echo\) >>new.txt

drivegrabber copy
duck copy
EasyBoot copy
hexedit copy
Linksys Driver copy
Linksys Driver2 copy
loadset copy
mysite copy
New Folder copy

What I would like is

copy drivegrabber
copy duck
copy EasyBoot
copy hexedit
copy Linksys Driver
copy Linksys Driver2
copy loadset
copy mysite
copy New Folder

Somewhere in the script it's adding to the end rather than the beginning.
If I can get it to work, later on I will use a variable as the first word will change.
Prefer not to use a third party program.


See More: Add command to lines in a text file

Report •


#1
January 16, 2011 at 13:19:27
Well, I don't know what the majority of that is doing, but try changing this:

echo/|set /p =%%a%addtext% & echo\ & echo\

To:

echo/|set /p =%addtext%%%a & echo\ & echo\

Can I put a question here?


Report •

#2
January 16, 2011 at 19:06:05
Thank you, thank you thank you.

Works perfectly.

I have been pulling my hair out for hours.


Report •

#3
January 16, 2011 at 19:58:09
No problem, glad I could help.

Can I put a question here?


Report •

Related Solutions

#4
January 16, 2011 at 20:17:40
download gawk (see my sig) and use this one liner
gawk "{print "copy "$0}" file

short and sweet.

GNU win32 packages | Gawk


Report •


Ask Question