Computing.Net > Forums > Programming > Find and replace a string in a file

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.

Find and replace a string in a file

Reply to Message Icon

Name: vicky29
Date: May 13, 2009 at 02:15:20 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi,
I have a file which contains the name of various SQL scripts, like...
T1.sql;
t2.sql;
t3.sql;

inside these sql scripts i have a commit statement at the end of file like..
commit;

After this commit i want to add a exit statement so it will look like..
commit;
exit;

How can i do it through a batch file...
Please help.



Sponsored Link
Ads by Google

Response Number 1
Name: Valerie (by Garibaldi)
Date: May 13, 2009 at 03:00:50 Pacific
Reply:

What does it mean?

I have a file which contains the name of various SQL scripts, like...
T1.sql;

inside these sql scripts i have a commit statement

Do you mean that the file contains nothing but the names of the SQL scripts or do you mean that you have a directory containing SQL scripts?

Your subject is "Find and replace a string in a file". Find what string and replace it with what?


0

Response Number 2
Name: vicky29
Date: May 13, 2009 at 04:16:30 Pacific
Reply:

no, this is a normal file like a text file, it contains the names of different sql scripts. Inside those scripts at the end of the script a "commit" is there and i have to append a exit after the commit..

commit;
exit;


0

Response Number 3
Name: Valerie (by Garibaldi)
Date: May 13, 2009 at 04:48:51 Pacific
Reply:

Try this. Replace filename1.txt with the name of the file containing the sql filenames only. path is the path to where the actual sql files are located.

:: Code begins...
@echo off
cls

setlocal enabledelayedexpansion

for /f %%1 in (filename1.txt) do (
    set filename=%%1
    echo exit;>>path\!filename!
)
:: Code ends...

Good luck.

V.


0

Response Number 4
Name: Mechanix2Go
Date: May 13, 2009 at 04:57:42 Pacific
Reply:

for /f "tokens=* delims= " %%a in (myfile) do (
echo exit, >> %%a
)


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

M2


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 Programming Forum Home


Sponsored links

Ads by Google


Results for: Find and replace a string in a file

find and replace string in a file www.computing.net/answers/programming/find-and-replace-string-in-a-file/19987.html

Find and replace a symbol in many t www.computing.net/answers/programming/find-and-replace-a-symbol-in-many-t/15915.html

find and replace ultra with extra in files www.computing.net/answers/programming/find-and-replace-ultra-with-extra-in-files/19290.html