4

I need a batch file which searches a text file for a string and replaces it with another string. I tried to do something like this but it doesn't work. Can anyone tell me what I'm doing wrong?

@echo off
setLocal DisableDelayedExpansion

if not exist "%1" (echo FindAndReplace: File Not Found)
set /p findX= Find ?
set /p replaceWithX= Replace With ?

for /f "tokens=* delims= " %%G in (%1) do (
    set str=%%G
    setLocal EnableDelayedExpansion
    set str=!str:[%findX%]=[%replaceWithX%]!
    >> %1.txt echo(!str!
    endlocal
)
Community
  • 1
  • 1
Milad
  • 4,901
  • 5
  • 32
  • 43

1 Answers1

0

A bit of code that would help would be the find command here is the help menu of it

Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V         Displays all lines NOT containing the specified string.
/C         Displays only the count of lines containing the string.
/N         Displays line numbers with the displayed lines.
/I         Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string"   Specifies the text string to find.
[drive:][path]filename
         Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
fftk4323
  • 130
  • 1
  • 12