copy “all contain of file.txt ” and “replace word in other text file with it ” in cmd using any script and any utility

Posted on

Problem :

I have two files:

  • file1.txt
  • file2.txt


wget --ftp-user=ezyro_19988709 --http-password=.......



So now I want to put password from file2 to file1 and replace the dotted area. Now after merging two file output should be like this:

wget --ftp-user=ezyro_19988709 --http-password=password" 

How would I go about this?

Solution :

You should give this a shoot:

Just create a file with .bat extension, then put the folowing code in the bat file, you need to create your files (file1.txt that contains the command line, and file2.txt that contains the password), put this two files in the same directory as the .bat file.

Then execute the file, that should work, please tell me if there is any errors.

set replacestr=""
for /F "tokens=*" %%a in (file2.txt) do call :Foo %%a
goto End

set replacestr=%1

call :innerloop  

echo %replacestr%
call :FindReplace "......." %replacestr% file1.txt

exit /b 

:FindReplace <findstr> <replstr> <file>
set tmp="%temp%tmp.txt"
If not exist %temp%_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
  for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
    echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
    <%%a cscript //nologo %temp%_.vbs "%~1" "%~2">%tmp%
    if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
del %temp%_.vbs
exit /b

>%temp%_.vbs echo with Wscript
>>%temp%_.vbs echo set args=.arguments
>>%temp%_.vbs echo .StdOut.Write _
>>%temp%_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%_.vbs echo end with

If you have Powershell installed on your Windows you can open it up and launch this command:

(Get-Content fullPathToFile2.txt).replace('string', (Get-Content fullPathToFile1.txt) ) | Set-Content fullPathToFile2.txt


(Get-Content I:b.txt).replace('5', (Get-Content I:a.txt) ) | Set-Content I:b.txt

Leave a Reply

Your email address will not be published. Required fields are marked *