1.

Solve : Need help for insert?

Answer»

I want to insert text in front of every lines. Is there anyone know how to do easy batch file?@echo off>newfile.txt
for /f "tokens=*" %%a in (oldfile.txt) do >>newfile.txt echo whatevertext%%asome other alternative
1) if you can DOWNLOAD stuffs to you COMP, get Gawk for WINDOWS(see my sig)
Code: [Select]C:\test>more file.txt
line 1
line 2

C:\test>gawk "{print \"whatever\"$0}" file.txt
whateverline 1
whateverline 2


2) vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFile= "C:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
WScript.Echo "Whatever" & objFile.ReadLine
Loop
save as myscript.vbs and on command line:
Code: [Select]C:\test>cscript /nologo myscript.vbs
Whateverline 1
Whateverline 2


Quote from: Reno on April 07, 2009, 11:42:08 PM

@echo off>newfile.txt
for /f "tokens=*" %%a in (oldfile.txt) do >>newfile.txt echo whatevertext%%a

thanks for your help. It's work but if I have so many files in the DIRECTORY then I want to insert text for every files. Is there any other varibles that I have to put in?use another loop to go through all your files.Quote from: akeker on April 08, 2009, 12:57:59 AM
thanks for your help. It's work but if I have so many files in the directory then I want to insert text for every files. Is there any other varibles that I have to put in?

Code: [Select]@echo off

for %%$ in (*.txt) do (
echo Processing %%$ --^> new_%%$ 2>new_%%$
for /f "tokens=*" %%a in (%%$) do >>new_%%$ echo whatevertext%%a
)Quote from: Reno on April 08, 2009, 01:10:47 AM
Code: [Select]@echo off

for %%$ in (*.txt) do (
echo Processing %%$ --^> new_%%$ 2>new_%%$
for /f "tokens=*" %%a in (%%$) do >>new_%%$ echo whatevertext%%a
)

Thanks again. it's work very well indeed. I wish you have all you want.


Discussion

No Comment Found