Computing.Net > Forums > Programming > batch to change lines in a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch to change lines in a file

Reply to Message Icon

Name: chestm
Date: March 11, 2009 at 10:08:30 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: March 11, 2009 at 10:16:16 Pacific
Reply:

for /?
Is this a classroom assignment?

--
Holla.


0

Response Number 2
Name: chestm
Date: March 11, 2009 at 10:23:22 Pacific
Reply:

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.


0

Response Number 3
Name: Holla
Date: March 12, 2009 at 02:15:50 Pacific
Reply:

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.


1

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Basic Variable tiff to excel



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch to change lines in a file

Script to remove lines from a file www.computing.net/answers/programming/script-to-remove-lines-from-a-file/7090.html

How to remove end-of-line in a file www.computing.net/answers/programming/how-to-remove-endofline-in-a-file/10873.html

To cut and paste a set of lines from a file www.computing.net/answers/programming/to-cut-and-paste-a-set-of-lines-from-a-file/20198.html