| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
Batch File Question
|
Original Message
|
Name: ianwillo
Date: June 28, 2007 at 00:59:04 Pacific
Subject: Batch File QuestionOS: XPCPU/Ram: naModel/Manufacturer: na |
Comment: Hello All. I have a test file with a lot of lines of text located in: C:\Test\go.txt What I want to be able to do is edit a line of text in the file that reads: C:\Temp\ to Y:\Temp\ (or another path) Could anyone please help?? Cheers Ian.
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: IVO
Date: June 28, 2007 at 02:26:48 Pacific
|
Reply: (edit)@Echo Off > C:\Test\go.out SetLocal EnableDelayedExpansion For /f "tokens=* delims=" %%i in (C:\Test\go.txt) Do ( Set Row=%%i Set Row=!Row:C:\Temp\=Y:\Temp\! Echo !Row!>> C:\Test\go.out) Echo Del C:\Test\go.txt Echo Ren C:\Test\go.out go.txt The script above replaces *each* occurence of C:\Temp\ with Y:\Temp\ and stores the result into the go.out file. When you are sure all goes fine, remove the Echo in front of Del and Ren commands to get the go.txt edited. Replace the Y:\Temp\ string with the wished path if necessary.
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: ghostdog
Date: June 29, 2007 at 00:46:11 Pacific
|
Reply: (edit)here's one in vbscript [code] Dim pattern,newPattern,objFSO,objFile Const ForReading=1 pattern="c:\temp" newPattern="y:\temp" Set objFSO= CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\go.txt", 1) Do Until objFile.AtEndOfLine line=Replace(objFile.ReadLine,pattern,newPattern) WScript.Echo line Loop [/code] save as myscript.vbs and run from command line: cscript myscript.vbs > outputfile
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home