Have multiple text files in a folder Wanted to delete the first line and replace with a specific sentence
However the first line in every text file contain different words so the find and replace does not work
How to batch edit all the files without open and close every file?
Regards
John
@echo off & setLocal EnableDELAYedeXpansion for /f "tokens=* delims= " %%a in ('dir/b/a-d *.txt') do (
> new echo.This is my string
for /f "skip=1 tokens=* delims= " %%i in (%%a) do (
>> new echo.%%i
)
move /y new %%a
)
=====================================
Helping others achieve escape felicityM2
Hi Mechanix, Should the code be input into a text file and rename the extension to .bat and put the file in the folder to double click? Sorry for the newbie qns
Where should the specific sentence to replace the first line be in the code?
"Should the code be input into a text file and rename the extension to .bat and put the file in the folder to double click?" yes
Put your text where I have:
This is my string
=====================================
Helping others achieve escape felicityM2
Hi mechanix Didn't mention that the sentence contain multiple comma and multiple < > symbols
The symbols seems to mess with the code u provide. Tried ( ) the sentence but not valid
Put the sentence in a file called SENTENCE and use this: =================================================
@echo off & setLocal EnableDELAYedeXpansionfor /f "tokens=* delims= " %%a in ('dir/b/a-d *.txt') do (
copy sentence new > nul
for /f "skip=1 tokens=* delims= " %%i in (%%a) do (
>> new echo.%%i
)
move /y new %%a
)
=====================================
Helping others achieve escape felicityM2
Hi Mechanix, Create a text file call sentence and input <name>,<per>,<koo> in the first line
Create a batch file with the code u provide
All in the same folder
However the <name>,<per>,<koo> didn't input into the text files instead the first line was deleted and the rows are move to first line
Also only text files with name without space in the name are processed. Text file with space in the name are not processed in the first line
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |