batch to change lines in a file

March 11, 2009 at 10:08:30
Specs: Windows XP
i would like to create a file that preforms 2 operations: 1. finds an line in a file goes one line above that and inserts a line and a string statement. i.e.

find line paul
above line paul insert Apple

and 2. changes certain lines in a file to another line. For instance:
Said file has 100 lines
for lines 30 - 80 change john to jason if john is present in that line.
for lines 30 - 80 change amy to angie if amy is present in that line.

lines 30 - 80may change per file with variable key words is there a way to input that key word?

I would like to do this as a batch file but I've also been recomended to use perl. whichever will be easiest to implement is what I'd like to do.
any help in this matter would be most appreciated.


See More: batch to change lines in a file

Report •


#1
March 11, 2009 at 10:16:16
for /?
Is this a classroom assignment?

--
Holla.


Report •

#2
March 11, 2009 at 10:23:22
No this is for at work and the information is sensitive so I can't go into an actual file description; however I hope this is sufficient.

Report •

#3
March 12, 2009 at 02:15:50
Untested: i am only providing general flow.
setlocal EnableDelayedExpansion
set linecount=1
for /f "tokens=*" %%a in (inputfile.txt) do (
set ReadLine=%%a
if ReadLine=paul echo Apple >> OutputFile.txt
if !linecount! leq 30 (
set Outline=!ReadLine:john=Jason!
) else if !linecount! leq 80 (
set Outline=!ReadLine:amy=angie!
)
set /a varcount+=1
>>OutputFile.txt echo !Outline!
)

--
Holla.


Report •

Related Solutions


Ask Question