Computing.Net > Forums > Windows XP > Batch file read and edit a line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file read and edit a line

Reply to Message Icon

Name: AlbitzT
Date: November 19, 2008 at 04:10:54 Pacific
OS: XP/2k3
CPU/Ram: NA
Product: NA
Comment:

Example of current batch file:

Line1
Line2
Line3
Line4
MY PROG NAME=%PROGNAME%
Line6
Line7
SET THIS IS IT=
LINE9
MY PROG NAME=
LINE11


I need my batch file to search the existing batch file and edit the "MY PROG NAME=" line to "MY PROG NAME=C:\Program Files..."

The catch is their are two of the same entries. IE: MY PROG NAME=%PROGNAME% and MY PROG NAME=

The second entry will always be on the same line in the batch file if that helps.

**This is not the actual file but a lot shorter for example purposes**

If any additional info is required please let me know.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 19, 2008 at 06:18:01 Pacific
Reply:

@echo off & setLocal EnableDelayedExpansion > newfile

for /f "tokens=* delims= " %%a in (my.bat) do (
set /a N+=1
if !N! equ 10 (
echo MY PROG NAME=C:\Program Files... >> newfile
) else (
echo %%a >> newfile
)
)


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

M2


0

Response Number 2
Name: AlbitzT
Date: November 22, 2008 at 08:24:33 Pacific
Reply:

Worked like a charm. Thanks for your help.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch file read and edit a line

Batch file: Reading date/file name www.computing.net/answers/windows-xp/batch-file-reading-datefile-name-/95129.html

Batch File reading a Text File www.computing.net/answers/windows-xp/batch-file-reading-a-text-file/153554.html

Reading and writing to a file in DOS www.computing.net/answers/windows-xp/reading-and-writing-to-a-file-in-dos/178103.html