Find and replace in a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sri2002
Posts: 4
Joined: 20 May 2013 21:43

Find and replace in a file

#1 Post by sri2002 » 20 May 2013 22:06

I have script which generates SQL's with variables.

@echo off

set "YYYY=2013"
set "YY=13"
set "MM=03"
set "LOCATION=D://DCOUMENTS/SQLSCRIPT/"

select count(*) from table1 where filedirectory='XXXXX' and file_name like 'ABC_percentage_%YYYY%%MM%__.txt'; >> %LOCATION%Generated_Script.sql

select count(*) from table2 where filedirectory='XXXXX' and file_name like 'ABC_percentage_%YYYY%%MM%__.txt'; >> %LOCATION%Generated_Script.sql

select count(*) from table3 where filedirectory='XXXXX' and file_name like 'ABC_percentage_%YYYY%%MM%__.txt'; >> %LOCATION%Generated_Script.sql

--After loading all sql's INTO %LOCATION%Generated_Script.sql. I want to find "percentage" and replace with "%" character.

Can someone help me to create a script finding "percentage" and replace with "%". I tried to create but its not working may be because of % character.

Appreciate your help in this. thanks in advance

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find and replace in a file

#2 Post by foxidrive » 21 May 2013 00:53

echo %% will create a single % character

Show us the code that you have tried.

sri2002
Posts: 4
Joined: 20 May 2013 21:43

Re: Find and replace in a file

#3 Post by sri2002 » 21 May 2013 05:32

foxidrive wrote:echo %% will create a single % character

Show us the code that you have tried.


Thanks foxidrive.

Your tip help me to resolve the issue. Now I dont need to find and replace it.

@echo off

set "YYYY=2013"
set "YY=13"
set "MM=03"
set "LOCATION=D://DCOUMENTS/SQLSCRIPT/"

select count(*) from table1 where filedirectory='XXXXX' and file_name like 'ABC_%%_%YYYY%%MM%__.txt'; >> %LOCATION%Generated_Script.sql

select count(*) from table2 where filedirectory='XXXXX' and file_name like 'ABC_%%_%YYYY%%MM%__.txt'; >> %LOCATION%Generated_Script.sql

select count(*) from table3 where filedirectory='XXXXX' and file_name like 'ABC_%%_%YYYY%%MM%__.txt'; >> %LOCATION%Generated_Script.sql

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find and replace in a file

#4 Post by foxidrive » 21 May 2013 06:13

sri2002 wrote:Thanks foxidrive.

Your tip help me to resolve the issue. Now I dont need to find and replace it.


That's great. It's better to solve the issue in the first instance. :)

Post Reply