Batch, Insert String

May 2, 2009 at 03:27:17
Specs: Microsoft Windows Vista Business, 2.2 GHz / 3582 MB
I am trying to make a batch file that inserts a string at the beginning of every line of a text document and at the end of a line. eg.

(String Here)test123456(String Here2)
(String Here)test(String Here2)
(String Here)1234test(string Here2)

ect.


See More: Batch, Insert String

Report •


#1
May 2, 2009 at 04:58:14
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=* delims=" %%a in (myfile) do (
echo STRING %%a STRING >> newfile
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
May 2, 2009 at 16:57:37
Thanks, that is exactly what i wanted. :D
Another thing, how do i delete the strings only at the end of the line

test123456(Delete String)
9784654613054086(Delete String)

ect.


Report •

#3
May 3, 2009 at 05:13:07
Do you mean a particular string? Or whatever the last string happens to be? Big difference.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
May 3, 2009 at 22:52:44
ummm, i need to remove the " at the end of every line in a text document (instead of deleting them all 1 by 1)
eg.

text"
text1"
text10"
text50"

ect.

Might be something like this, but it only deletes the characters from the start of the row.
|
˅

SetLocal EnableDelayedExpansion
for /f "tokens=1*" %%a in (text1.txt) do (
set Row=%%a %%b
set Row=!Row:~1!
echo.!Row!>> text2.txt


)


Report •

#5
May 4, 2009 at 01:51:21
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=*" %%a in (myfile) do (
set Row=%%a
set LC=!Row:~-1!
set DQ="
if !LC!==!DQ! (
set Row=!Row:~0,-1!
)
echo.!Row!>> newfile
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#6
May 4, 2009 at 02:41:48
Awesome, Thanks

Report •

#7
May 4, 2009 at 03:45:13
lol, sorry i have another issue,

@echo off > List2.txt & setLocal EnableDelayedExpansion

for /f "tokens=* delims=" %%a in (List.txt) do (
echo "for /f "delims=*" %%i in ('dir /b /s "*%%a*"') do del /p /s "%%i"">> List2.txt
)

%%a is the text in the list.txt
eg.
song1.mp3
song2.mp3
song3.mp3

I have an issue where it: (list2.txt)
"for /f "delims=*" %i in ('dir /b /s "*song1.m3.mp3*"') do del /p /s "%i""
"for /f "delims=*" %i in ('dir /b /s "*song2.m3.mp3*"') do del /p /s "%i""

ect.

where the %i is, it is missing another % should be %%i
I don't know why it does that...
Any help?


Report •

#8
May 4, 2009 at 07:04:05
I don't know what you're trying to accomplish but you probably need to add an extra %


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#9
May 5, 2009 at 00:03:48
This might help:

http://img9.imageshack.us/img9/7346...

Song_list2.txt will be a batch file by the way


Report •


Ask Question