| 1. |
Solve : Use batch file to insert text in a text file after a word i specify?? |
|
Answer» To put it in plain terms guys n gals what i would like to know is if this is possible? guys wow replies were excellent and very fast thanks very much, this forum rocks. quick question to batcher, i noticed equ 12 does that insert the text i want on line 12 cause there is like hundreds of different lines and it is near the end and it is not on the same line anytime, i like the look of yours best as it seems the simplest so COULD you edit it to insert the text after the word i originally specified? is that possible?if line 12 always have the word CLEANUP, then the batch solution should be ok. Otherwise, need to change it to something more flexible.does my solution work ? Quote from: rytech on April 22, 2009, 06:22:01 AM quick question to batcher, i noticed equ 12 does that insert the text i want on line 12 cause there is like hundreds of different lines and it is near the end and it is not on the same line anytime, i like the look of yours best as it seems the simplest so could you edit it to insert the text after the word i originally specified? Everything is possible. Try this one. Code: [Select]echo off set SrcFolder=C:\test1 set DstFolder=C:\test2 for %%a in ("%SrcFolder%\*.txt") do ( (for /f "usebackq delims=" %%h in ("%%a") do ( echo.%%h if "%%h" equ "SCHEDULES CLEANUP" ( echo SYS DUEGATE 60 05:00 echo DISPLAY SCHED 00:30 01:30 ) ))>"%DstFolder%\%%~nxa" ) Batcher your the man thanks very much buddy Devcom i never tried it mate cause the line number thing you had in yours but batchers done the job and i edited the batch file to delete the un needed folder once it had done it so it's all sorted but i need to know if it is possible to delete some text in the file and replace it, i need to replace the date with the date i am working with rather than the date set in the files as well it was just i forgot about that so i have: ECHO OFF set SrcFolder=C:\Test set DstFolder=C:\Test1 for %%a in ("%SrcFolder%\*.txt") do ( (for /f "usebackq delims=" %%h in ("%%a") do ( echo.%%h if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 ) ))>"%DstFolder%\%%~nxa" ) Where SYS CONFIG 20090327 i want that replaced with SYS CONFIG 20090427, is that possible, this question goes to my man batcher lol or anyone with the knowledge cause i aint got it try to change this: Code: [Select] echo.%%h if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 )to Code: [Select] if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 ) else ( echo.%%h ) should work devcom sorry to be a bloody pain but it says the system could not find the path specified, here is what i have, can you think of anything that looks wrong? ECHO OFF set SrcFolder=c:\test set DstFolder=C:\test1 for %%a in ("%SrcFolder%\*.txt") do ( (for /f "usebackq delims=" %%h in ("%%a") do ( if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 ) else ( echo.%%h ) ))>"%DstFolder%\%%~nxa" ) ECHO. ECHO Done! ECHO. PAUSE CLS |
|