Editing multiple files

September 3, 2010 at 10:14:26
Specs: Windows XP
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


See More: Editing multiple files

Report •


#1
September 3, 2010 at 14:15:18
@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 felicity

M2


Report •

#2
September 3, 2010 at 23:21:05
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?


Report •

#3
September 4, 2010 at 05:34:34
"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 felicity

M2


Report •

Related Solutions

#4
September 4, 2010 at 10:26:22
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


Report •

#5
September 6, 2010 at 07:55:36
Put the sentence in a file called SENTENCE and use this:

=================================================
@echo off & setLocal EnableDELAYedeXpansion

for /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 felicity

M2


Report •

#6
September 6, 2010 at 09:45:45
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


Report •


Ask Question