Batch file to Find and Replace a Substring Inside a File

View: New views
20 Messages — Rating Filter:   Alert me  

Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am trying to write a batch file that would replace a substring inside
a file with another substring, and than execute that file using isql
utility.

I did take care of the second part(isql), but don't have a lot of luck
with find/replace. Any help will be extremely appreciated.


Re: Batch file to Find and Replace a Substring Inside a File

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 27 Oct 2008 15:22:57 -0000, "AllaGelfand" <allagelfand@...>
wrote:

>I am trying to write a batch file that would replace a substring inside
>a file with another substring, and than execute that file using isql
>utility.
>
>I did take care of the second part(isql), but don't have a lot of luck
>with find/replace. Any help will be extremely appreciated.

SED is a stream editor that utilised regular expressions.

GNUSED is the port/version I use.

Some examples would help with creating some code...

Re: Batch file to Find and Replace a Substring Inside a File

by Parag P. Doke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What was suggested by Mic (using SED) is definitely a better option.
Here's my attempt at creating a plain batch to replace strings. It
hasn't been tested for all characters, huge files, number of
files....but nevertheless since the topic has come up....
=====
@echo off
set "TempCode=%TEMP%\Temp.bat"
set "TempContent=%TEMP%\%~nx1.new"
for /f "delims=" %%i in ('type %1') do (
    echo @echo off>"%TempCode%"
    echo set "var1=%%i">>"%TempCode%"
    echo set "var1=%%var1:%2=%3%%">>"%TempCode%"
    echo set "var1=%%var1:<=^<%%">>"%TempCode%"
    echo set "var1=%%var1:>=^>%%">>"%TempCode%"
    echo set "var1=%%var1:|=^|%%">>"%TempCode%"
    echo echo %%var1%%>>"%TempCode%"
    call "%TempCode%">>"%TempContent%"
)
if exist "%TempCode%" del "%TempCode%"
if exist "%TempContent%" del %1 & move "%TempContent%" %1
=====
I should not forget to mention Veli Pekka Tatila's name. Many parts of
this came up while exchanging emails with him.

Regards,
Parag

On Tue, Oct 28, 2008 at 3:22 AM, foxidrive <foxidrive@...> wrote:

> On Mon, 27 Oct 2008 15:22:57 -0000, "AllaGelfand" <allagelfand@...>
> wrote:
>
>>I am trying to write a batch file that would replace a substring inside
>>a file with another substring, and than execute that file using isql
>>utility.
>>
>>I did take care of the second part(isql), but don't have a lot of luck
>>with find/replace. Any help will be extremely appreciated.
>
> SED is a stream editor that utilised regular expressions.
>
> GNUSED is the port/version I use.
>
> Some examples would help with creating some code...
>
>



--
Parag P. Doke
http://paragpdoke.blogspot.com

Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

this is the code I am trying to make to work, but for some reason the
final part is failing on me:

@echo off
cls
set /p DBNAME=Please enter Database name:

if '%DBNAME%'=="" goto usage
echo You entered:  %DBNAME%
if '%DBNAME%'=="APP_CONFIG" goto CFGReplace
:CFGReplace
set replace=Substitute_CFG_DB_Name
echo %DBNAME% will be replaced with %replace%
goto end
:usage
echo Must enter a valid database name like APP_CONFIG or APP_WORK or
DEV_FACETS...
:end
echo.
pause

find /N "APP_CONFIG" c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql
pause

@echo off

set txtfile=c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql
for /f "tokens=*" %%a in (%txtfile%) do
(
   set newline=%%a
   echo %%a%%
   pause
   set newline=%%newline:%search%=%replace%%%
 
   pause
   ::set newline=%%newline:%search%=%replace%%%
   ::call echo %%newline%% >>%newfile%
)
pause


--- In batchworld@..., foxidrive <foxidrive@...> wrote:
>
> On Mon, 27 Oct 2008 15:22:57 -0000, "AllaGelfand" <allagelfand@...>
> wrote:
>
> >I am trying to write a batch file that would replace a substring
inside
> >a file with another substring, and than execute that file using
isql
> >utility.
> >
> >I did take care of the second part(isql), but don't have a lot of
luck
> >with find/replace. Any help will be extremely appreciated.
>
> SED is a stream editor that utilised regular expressions.
>
> GNUSED is the port/version I use.
>
> Some examples would help with creating some code...
>



Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Parag,

Thank you! How do you, actually, execute this file?
What parameters does it require.

thank you,
Alla


--- In batchworld@..., "Parag P. Doke" <paragpdoke@...>
wrote:

>
> What was suggested by Mic (using SED) is definitely a better option.
> Here's my attempt at creating a plain batch to replace strings. It
> hasn't been tested for all characters, huge files, number of
> files....but nevertheless since the topic has come up....
> =====
> @echo off
> set "TempCode=%TEMP%\Temp.bat"
> set "TempContent=%TEMP%\%~nx1.new"
> for /f "delims=" %%i in ('type %1') do (
>     echo @echo off>"%TempCode%"
>     echo set "var1=%%i">>"%TempCode%"
>     echo set "var1=%%var1:%2=%3%%">>"%TempCode%"
>     echo set "var1=%%var1:<=^<%%">>"%TempCode%"
>     echo set "var1=%%var1:>=^>%%">>"%TempCode%"
>     echo set "var1=%%var1:|=^|%%">>"%TempCode%"
>     echo echo %%var1%%>>"%TempCode%"
>     call "%TempCode%">>"%TempContent%"
> )
> if exist "%TempCode%" del "%TempCode%"
> if exist "%TempContent%" del %1 & move "%TempContent%" %1
> =====
> I should not forget to mention Veli Pekka Tatila's name. Many parts
of
> this came up while exchanging emails with him.
>
> Regards,
> Parag
>
> On Tue, Oct 28, 2008 at 3:22 AM, foxidrive <foxidrive@...> wrote:
> > On Mon, 27 Oct 2008 15:22:57 -0000, "AllaGelfand"
<allagelfand@...>
> > wrote:
> >
> >>I am trying to write a batch file that would replace a substring
inside
> >>a file with another substring, and than execute that file using
isql
> >>utility.
> >>
> >>I did take care of the second part(isql), but don't have a lot of
luck

> >>with find/replace. Any help will be extremely appreciated.
> >
> > SED is a stream editor that utilised regular expressions.
> >
> > GNUSED is the port/version I use.
> >
> > Some examples would help with creating some code...
> >
> >
>
>
>
> --
> Parag P. Doke
> http://paragpdoke.blogspot.com
>



Re: Batch file to Find and Replace a Substring Inside a File

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 28 Oct 2008 13:20:11 -0000, "AllaGelfand" <allagelfand@...>
wrote:

>this is the code I am trying to make to work, but for some reason the
>final part is failing on me:
>
>@echo off
>cls
>set /p DBNAME=Please enter Database name:

Try this untested snippet, based on your code:

@echo off
cls
:start
set /p "DBNAME=Please enter Database name: "

if "%DBNAME%"=="" (
echo Must enter a valid database name like
echo APP_CONFIG or APP_WORK or DEV_FACETS...
pause
goto :start
)

echo You entered:  %DBNAME%

if /i "%DBNAME%"=="APP_CONFIG" set replace=Substitute_CFG_DB_Name
echo %DBNAME% will be replaced with %replace%
echo.
pause

find /N "APP_CONFIG" c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql
pause

set txtfile="c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql"

for /f "tokens=*" %%a in ('type %txtfile%') do call :next "%%a"
goto :EOF

:next
   set newline=%~1
   echo %newline%
   pause
   set newline=%%newline:%search%=%replace%%%
   echo %newline%
   pause
   >>%newfile% echo %newline%
pause

Re: Batch file to Find and Replace a Substring Inside a File

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 29 Oct 2008 07:54:38 +1100, foxidrive <foxidrive@...>
wrote:

Change this line to

>   set newline=%%newline:%search%=%replace%%%

this:

    call set newline=%%newline:%search%=%replace%%%


Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'll definitely try! How do I make sure the changes will take place inside the file?I noticed that sometimes it works on a screen, but nothing gets changed inside the same file.

Thank you very much!

--- On Tue, 10/28/08, foxidrive <foxidrive@...> wrote:
From: foxidrive <foxidrive@...>
Subject: Re: [BATCH WORLD] Batch file to Find and Replace a Substring Inside a File
To: batchworld@...
Date: Tuesday, October 28, 2008, 5:03 PM










   
            On Wed, 29 Oct 2008 07:54:38 +1100, foxidrive <foxidrive@yahoo. com.au>

wrote:



Change this line to



>   set newline=%%newline: %search%= %replace% %%



this:



call set newline=%%newline: %search%= %replace% %%




     

   
   
       
         
       
       








       


       
       


     

[Non-text portions of this message have been removed]


Re: Batch file to Find and Replace a Substring Inside a File

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 28 Oct 2008 16:53:34 -0700 (PDT), Alla Gelfand
<allagelfand@...> wrote:

>How do I make sure the changes will take place inside the file?
>I noticed that sometimes it works on a screen, but nothing gets changed inside the same file.

You'd have to show the code you used - and also a sample of the sql file so
we can duplicate the problem.


Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'll attach them tomorrow!

Thank you very much!

--- On Tue, 10/28/08, foxidrive <foxidrive@...> wrote:
From: foxidrive <foxidrive@...>
Subject: Re: [BATCH WORLD] Batch file to Find and Replace a Substring Inside a File
To: batchworld@...
Date: Tuesday, October 28, 2008, 8:14 PM










   
            On Tue, 28 Oct 2008 16:53:34 -0700 (PDT), Alla Gelfand

<allagelfand@ yahoo.com> wrote:



>How do I make sure the changes will take place inside the file?

>I noticed that sometimes it works on a screen, but nothing gets changed inside the same file.



You'd have to show the code you used - and also a sample of the sql file so

we can duplicate the problem.




     

   
   
       
         
       
       








       


       
       


     

[Non-text portions of this message have been removed]


Re: Batch file to Find and Replace a Substring Inside a File

by giskier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can find an article about this, checking knowledge base article KB007 in http://www.steppingsoftware.com/ssportal/Support/tabid/57/Default.aspx 

I hope you will find it helpful.

GISkier


AllaGelfand wrote:
I am trying to write a batch file that would replace a substring inside
a file with another substring, and than execute that file using isql
utility.

I did take care of the second part(isql), but don't have a lot of luck
with find/replace. Any help will be extremely appreciated.

Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I changed the file to the following, but it still doesn't work that well. I am attaching the sql file, I am trying to parse.
 
@echo off
cls
:start
set /p "DBNAME=Please enter Database name: "
if "%DBNAME%"== "" (
echo Must enter a valid database name like
echo APP_CONFIG or APP_WORK or DEV_FACETS.. .
pause
goto :start
)
echo You entered: %DBNAME%
if /i "%DBNAME%"== "APP_CONFIG" set replace=Substitute_ CFG_DB_Name
echo %DBNAME% will be replaced with %replace%
pause
find /N "APP_CONFIG" c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql
pause
set txtfile="c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql"
for /f "tokens=*" %%a in ('type %txtfile%'|find %DBNAME%) do call :next "%%a"
goto :EOF
:next
set newline=%~1
::echo %newline%
::pause
call set newline=%%newline:%DBNAME%=%replace%%%
echo %newline%
pause
>>%newfile% echo %newline%
pause
 


--- On Tue, 10/28/08, foxidrive <foxidrive@...> wrote:

From: foxidrive <foxidrive@...>
Subject: Re: [BATCH WORLD] Batch file to Find and Replace a Substring Inside a File
To: batchworld@...
Date: Tuesday, October 28, 2008, 5:03 PM






On Wed, 29 Oct 2008 07:54:38 +1100, foxidrive <foxidrive@yahoo. com.au>
wrote:

Change this line to

> set newline=%%newline: %search%= %replace% %%

this:

call set newline=%%newline: %search%= %replace% %%

 














     

[Non-text portions of this message have been removed]


Re: Batch file to Find and Replace a Substring Inside a File

by Parag P. Doke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All.Mic please correct me if I'm wrong in understanding ...but there are
2 things I wanted to say (to Alla):
[It is likely that I might have missed out on some of the lines in the
thread...apologies if that is the case.]

1) The script seems to be substituting and echoing only lines that have
%DBNAME% string(s) in them.
===Input sql file===
Some text some text
Some text some text APP_CONFIG                  <= Only this line seems to
be replaced in the new file.
Some text some text some text some text
===Input sql file===
The reason for this was line:
for /f "tokens=*" %%a in ('type %txtfile%'|find %DBNAME%) do call :next
"%%a"
===Output echoed===
Some text some text Substitute_CFG_DB_Name
===Output echoed===
The 1st and 3rd line will go away.

If the entire sql file should be echoed (not only the line with the DBNAME),
then the find needs to be omitted:
for /f "tokens=*" %%a in ('type %txtfile%') do call :next "%%a"

2) Also, (again maybe I'm mistaken), but if you wanted only the concerned
lines to be displayed, the line mentioned above should have been:
for /f "tokens=*" %%a in ('type %txtfile%^|find %DBNAME%') do call :next
"%%a"

Alla asked me in an earlier reply about how to use the piece of script I
shared. This is what worked for me.
1) Save the following lines in a script "replace.bat".
2) Assuming the sql file to be modified is "input.sql" in the same location
as replace.bat, in a cmd type:
replace.bat input.sql APP_CONFIG Substitute_CFG_DB_Name

However, the sed method mentioned by Mic in the other thread is much
powerful than plain batch code.

Thanks,
Parag


On Wed, Oct 29, 2008 at 7:18 PM, Alla Gelfand <allagelfand@...> wrote:

>   I changed the file to the following, but it still doesn't work that
> well. I am attaching the sql file, I am trying to parse.
>
>
> @echo off
> cls
> :start
> set /p "DBNAME=Please enter Database name: "
> if "%DBNAME%"== "" (
> echo Must enter a valid database name like
> echo APP_CONFIG or APP_WORK or DEV_FACETS.. .
> pause
> goto :start
> )
> echo You entered: %DBNAME%
> if /i "%DBNAME%"== "APP_CONFIG" set replace=Substitute_ CFG_DB_Name
> echo %DBNAME% will be replaced with %replace%
> pause
> find /N "APP_CONFIG" c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql
> pause
> set txtfile="c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql"
> for /f "tokens=*" %%a in ('type %txtfile%'|find %DBNAME%) do call :next
> "%%a"
> goto :EOF
> :next
> set newline=%~1
> ::echo %newline%
> ::pause
> call set newline=%%newline:%DBNAME%=%replace%%%
> echo %newline%
> pause
> >>%newfile% echo %newline%
> pause
>
>
> --- On Tue, 10/28/08, foxidrive <foxidrive@...<foxidrive%40yahoo.com.au>>
> wrote:
>
> From: foxidrive <foxidrive@... <foxidrive%40yahoo.com.au>>
> Subject: Re: [BATCH WORLD] Batch file to Find and Replace a Substring
> Inside a File
> To: batchworld@... <batchworld%40yahoogroups.com>
> Date: Tuesday, October 28, 2008, 5:03 PM
>
> On Wed, 29 Oct 2008 07:54:38 +1100, foxidrive <foxidrive@yahoo. com.au>
> wrote:
>
> Change this line to
>
> > set newline=%%newline: %search%= %replace% %%
>
> this:
>
> call set newline=%%newline: %search%= %replace% %%
>
> [Non-text portions of this message have been removed]
>
>  
>



--
Parag P. Doke
http://paragpdoke.blogspot.com


[Non-text portions of this message have been removed]


Re: Batch file to Find and Replace a Substring Inside a File

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 30 Oct 2008 12:54:58 +0530, "Parag P. Doke" <paragpdoke@...>
wrote:

>The reason for this was line:
>for /f "tokens=*" %%a in ('type %txtfile%'|find %DBNAME%) do call :next "%%a"

Yes, spot on on both points.


Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Parag,

Thank you for your reply.
Here is what I really need to do:
I need to take the sql file, mentioned in the thread or any other sql
file, and replace some of the database references with substitute
strings, and save the file with substitutes in the same directory or
any other directory.
The echo on a screen is nice, but is not a purpose of the exercise.

The reason I am using DOS is simple, I don't want the input file to be
changed in a any way, as the isql utility that executes the sql file
once we revert back from substitutes sometimes doesn't like different
types of eol character that Windows version of SED in putting in, and
DOS version of SED is less powerful.

I'll try the script below to see how it is going to work as soon as I
come back to work.
Any suggestions are greatly appreciated, as I am practically under the
gun now;-)



--- In batchworld@..., "Parag P. Doke" <paragpdoke@...> wrote:
>
> Hi All.Mic please correct me if I'm wrong in understanding ...but
there are
> 2 things I wanted to say (to Alla):
> [It is likely that I might have missed out on some of the lines in the
> thread...apologies if that is the case.]
>
> 1) The script seems to be substituting and echoing only lines that have
> %DBNAME% string(s) in them.
> ===Input sql file===
> Some text some text
> Some text some text APP_CONFIG                  <= Only this line
seems to

> be replaced in the new file.
> Some text some text some text some text
> ===Input sql file===
> The reason for this was line:
> for /f "tokens=*" %%a in ('type %txtfile%'|find %DBNAME%) do call :next
> "%%a"
> ===Output echoed===
> Some text some text Substitute_CFG_DB_Name
> ===Output echoed===
> The 1st and 3rd line will go away.
>
> If the entire sql file should be echoed (not only the line with the
DBNAME),
> then the find needs to be omitted:
> for /f "tokens=*" %%a in ('type %txtfile%') do call :next "%%a"
>
> 2) Also, (again maybe I'm mistaken), but if you wanted only the
concerned
> lines to be displayed, the line mentioned above should have been:
> for /f "tokens=*" %%a in ('type %txtfile%^|find %DBNAME%') do call :next
> "%%a"
>
> Alla asked me in an earlier reply about how to use the piece of script I
> shared. This is what worked for me.
> 1) Save the following lines in a script "replace.bat".
> 2) Assuming the sql file to be modified is "input.sql" in the same
location

> as replace.bat, in a cmd type:
> replace.bat input.sql APP_CONFIG Substitute_CFG_DB_Name
>
> However, the sed method mentioned by Mic in the other thread is much
> powerful than plain batch code.
>
> Thanks,
> Parag
>
>
> On Wed, Oct 29, 2008 at 7:18 PM, Alla Gelfand <allagelfand@...> wrote:
>
> >   I changed the file to the following, but it still doesn't work that
> > well. I am attaching the sql file, I am trying to parse.
> >
> >
> > @echo off
> > cls
> > :start
> > set /p "DBNAME=Please enter Database name: "
> > if "%DBNAME%"== "" (
> > echo Must enter a valid database name like
> > echo APP_CONFIG or APP_WORK or DEV_FACETS.. .
> > pause
> > goto :start
> > )
> > echo You entered: %DBNAME%
> > if /i "%DBNAME%"== "APP_CONFIG" set replace=Substitute_ CFG_DB_Name
> > echo %DBNAME% will be replaced with %replace%
> > pause
> > find /N "APP_CONFIG" c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql
> > pause
> > set txtfile="c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql"
> > for /f "tokens=*" %%a in ('type %txtfile%'|find %DBNAME%) do call
:next

> > "%%a"
> > goto :EOF
> > :next
> > set newline=%~1
> > ::echo %newline%
> > ::pause
> > call set newline=%%newline:%DBNAME%=%replace%%%
> > echo %newline%
> > pause
> > >>%newfile% echo %newline%
> > pause
> >
> >
> > --- On Tue, 10/28/08, foxidrive
<foxidrive@...<foxidrive%40yahoo.com.au>>
> > wrote:
> >
> > From: foxidrive <foxidrive@... <foxidrive%40yahoo.com.au>>
> > Subject: Re: [BATCH WORLD] Batch file to Find and Replace a Substring
> > Inside a File
> > To: batchworld@... <batchworld%40yahoogroups.com>
> > Date: Tuesday, October 28, 2008, 5:03 PM
> >
> > On Wed, 29 Oct 2008 07:54:38 +1100, foxidrive <foxidrive@yahoo.
com.au>

> > wrote:
> >
> > Change this line to
> >
> > > set newline=%%newline: %search%= %replace% %%
> >
> > this:
> >
> > call set newline=%%newline: %search%= %replace% %%
> >
> > [Non-text portions of this message have been removed]
> >
> >  
> >
>
>
>
> --
> Parag P. Doke
> http://paragpdoke.blogspot.com
>
>
> [Non-text portions of this message have been removed]
>



Re: Batch file to Find and Replace a Substring Inside a File

by Klaus Meinhard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

AllaGelfand wrote:

> Any suggestions are greatly appreciated, as I am practically under the
> gun now;-)


If you're really planning to do a business strength solution with a
batch, you should stop trying to achieve success under braindead
command.com and use 4DOS. Download it from http://www.4dos.zzl.org/.
It's completely free and much more powerful than command.com. If you`re
not truly working under plain DOS but under some version of NT/XP/Vista,
use free TCC/LE from JP Software (www.jpsoft.com) which is the successor
to 4DOS. You won't need another tool for your job.

Install it and look at the help (F1 key!): You can open files in binary
mode (look at Variable Functions, @fileopen, @fileread, @fileseek),
parse a read line (look at @index, @instr, @left, @right, @replace) and
@filewrite the result to a new file. Simple and straightforward. If
you're interested after having a look and still need help (which I doubt
since you seem to know some programming) I'm here.

Mit freundlichem Gruß,

Klaus Meinhard


Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Klaus,
Danke shoene!
Thank you very much for your advice. I'll definitely give it a try,
allthough the reason I was going with DOS was simple - it is
ubiquitous, it doesn't require installation on any programmer's
machine, and doesn't need any maintenance, and can be run both
locally and in  CITRIX environment.

I'll keep you posted on the outcome.

Thank you,
Alla


--- In batchworld@..., "Klaus Meinhard" <k_meinhard@...>
wrote:
>
> AllaGelfand wrote:
>
> > Any suggestions are greatly appreciated, as I am practically
under the
> > gun now;-)
>
>
> If you're really planning to do a business strength solution with a
> batch, you should stop trying to achieve success under braindead
> command.com and use 4DOS. Download it from
http://www.4dos.zzl.org/.
> It's completely free and much more powerful than command.com. If
you`re
> not truly working under plain DOS but under some version of
NT/XP/Vista,
> use free TCC/LE from JP Software (www.jpsoft.com) which is the
successor
> to 4DOS. You won't need another tool for your job.
>
> Install it and look at the help (F1 key!): You can open files in
binary
> mode (look at Variable Functions, @fileopen, @fileread, @fileseek),
> parse a read line (look at @index, @instr, @left, @right, @replace)
and
> @filewrite the result to a new file. Simple and straightforward. If
> you're interested after having a look and still need help (which I
doubt
> since you seem to know some programming) I'm here.
>
> Mit freundlichem Gruß,
>
> Klaus Meinhard
>



Re: Batch file to Find and Replace a Substring Inside a File

by Klaus Meinhard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

> Thank you very much for your advice. I'll definitely give it a try,
> allthough the reason I was going with DOS was simple - it is
> ubiquitous, it doesn't require installation on any programmer's
> machine, and doesn't need any maintenance, and can be run both
> locally and in  CITRIX environment.
>
> I'll keep you posted on the outcome.

4DOS is just a (mostly compatible) replacement for command.com. But the
power to write batches is awesome. You have all the OS information that
Microsoft didn't bother to make available at your fingertips in the form
of internal variables, you can perform actions on files, strings, dates
etc. with internal functions, plus structural commands like
iff...then...else, gosub, switch...case...case...endswitch and much more
tha I can list here.

If you really want to write DOS batches in a business environment, 4DOS
is the way to go. You will understand a batch you've written even after
several years, while most clever and convoluted command.com batches are
incomprehensible even by their authors sometimes after a few weeks.

* Klaus Meinhard *
4DOS Info - Info for DOS
www.4dos.info


Re: Batch file to Find and Replace a Substring Inside a File

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Karl,
 
I just download freeware version is our folks here won't be paying for anything else, and I'll try to incorporate the conding I've done so far with this...
 
We'll see what's going to come out.
 
Again, vielen dank!
 
Alla

--- On Fri, 10/31/08, Klaus Meinhard <k_meinhard@...> wrote:

From: Klaus Meinhard <k_meinhard@...>
Subject: Re: [BATCH WORLD] Batch file to Find and Replace a Substring Inside a File
To: batchworld@...
Date: Friday, October 31, 2008, 12:14 PM







Hi,

> Thank you very much for your advice. I'll definitely give it a try,
> allthough the reason I was going with DOS was simple - it is
> ubiquitous, it doesn't require installation on any programmer's
> machine, and doesn't need any maintenance, and can be run both
> locally and in CITRIX environment.
>
> I'll keep you posted on the outcome.

4DOS is just a (mostly compatible) replacement for command.com. But the
power to write batches is awesome. You have all the OS information that
Microsoft didn't bother to make available at your fingertips in the form
of internal variables, you can perform actions on files, strings, dates
etc. with internal functions, plus structural commands like
iff...then.. .else, gosub, switch...case. ..case... endswitch and much more
tha I can list here.

If you really want to write DOS batches in a business environment, 4DOS
is the way to go. You will understand a batch you've written even after
several years, while most clever and convoluted command.com batches are
incomprehensible even by their authors sometimes after a few weeks.

* Klaus Meinhard *
4DOS Info - Info for DOS
www.4dos.info

 














     

[Non-text portions of this message have been removed]


Re: Batch file to Find and Replace a Substring Inside a File

by Klaus Meinhard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alla Gelfand wrote:

> I just download freeware version is our folks here won't be paying
> for anything else, and I'll try to incorporate the conding I've done
> so far with this...

There is only freeware 4DOS. It was a commercial application for many
years, very successful from the early nineties on and a must have in BBS
circles, which used it to parse their log files. And it didn't even have
@fileopen etc then. They worked with @line, @lines if you want to take a
look at that with 4DOS Help. 4DOS has been set free by its author some
years ago, when DOS apllications weren't a sound business proposition
any longer.

If you have any questions, post your code and I'll have a look or I'll
send you a skeleton batch you can flesh out.

* Klaus Meinhard *
4DOS Info - Info for DOS
www.4dos.info