Page 1 of 1

Prepending string to each line

Posted: 08 Jun 2012 02:05
by yigitozen
Hello, i need a windows batch script to prepend (insert to the beginning) to every line of a file:

string to insert:
"hello"

<input.txt>
dos
tips
forum

<output.txt>
hellodos
hellotips
helloforum

Can you suggest a solution?

Thank you,
Yiğit.

Re: Prepending string to each line

Posted: 08 Jun 2012 02:41
by foxidrive
What is your real data? Is it a path/filename like in the last example?

Code: Select all

@echo off
for /f "delims=" %%a in (filein.txt) do (
>>"fileout.txt" echo hello%%a
)

Re: Prepending string to each line

Posted: 08 Jun 2012 02:58
by yigitozen
hi foxidrive, i am trying to build an ant build.xml to include some files. by your help so far, i could achieve to convert:

/AS/lib/classes/configuration/ApiMessages.xml

into:
<classpath codebase="file:/AS/lib/classes/configuration/" archives="ApiMessages.xml" />


thank you, your code work as i needed. :) good day.

Re: Prepending string to each line

Posted: 08 Jun 2012 05:22
by prash11
@echo off
FOR /F "delims=" %%G IN (file_names.txt) DO (
set "FILE=%%G"
setlocal enabledelayedexpansion
set "file1=hello!FILE!"
echo !FILE!
echo !file1!>>output.txt
endlocal
)