Prepending string to each line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
yigitozen
Posts: 6
Joined: 07 Jun 2012 06:41

Prepending string to each line

#1 Post by yigitozen » 08 Jun 2012 02:05

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Prepending string to each line

#2 Post by foxidrive » 08 Jun 2012 02:41

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
)

yigitozen
Posts: 6
Joined: 07 Jun 2012 06:41

Re: Prepending string to each line

#3 Post by yigitozen » 08 Jun 2012 02:58

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.

prash11
Posts: 21
Joined: 27 Apr 2012 01:38

Re: Prepending string to each line

#4 Post by prash11 » 08 Jun 2012 05:22

@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
)

Post Reply