How do I Remove lines above a key word, remove the lines below another, and keep the lines between t

Q

Quentin

I have a text file with lines that I would like to remove above a
certain word and below another word.

Example:

1231231231234123423434
2341234123412341242141
234512353764316236234
1235635326235125134534
Recipe
345353453532542353245
52345235452456426515
23452362387487262346
32662356245724572457
234623624526
End Recipe
436452346467
5764743634734646
4563463456345

I would like to remove the lines from above Recipe and remove the
lines below End Recipe? Any help would be Greatly Appreciated!!
Thank you!
 
D

Duracel

To rephrase, what you want to do is write a new file containing only what is
in-between Recipie/End Recipie. So, open one file for reading (the file you
want to edit) and one for writing (create a temporary file). Then read in
lines from the first file until you find the keyword. Then search until you
find the second keyword. Then write out to the second file what you read
between finding the first keyword and the second keyword. Rinse and repeat.

Some tweaking required for me verboseenglish.NET code given above.
 
Q

Quentin

To rephrase, what you want to do is write a new file containing only what is
in-between Recipie/End Recipie. So, open one file for reading (the file you
want to edit) and one for writing (create a temporary file). Then read in
lines from the first file until you find the keyword. Then search until you
find the second keyword. Then write out to the second file what you read
between finding the first keyword and the second keyword. Rinse and repeat.

Some tweaking required for me verboseenglish.NET code given above.

I'm kind of new to vb.net so could you help me with some of the
coding. I know how to open read, create and write files but how do I
write what is between the key words to a temp file.

maybe something like:

line = inputfile.readline
while line <> Keyword1
output.writeline(line)
end while

then what should I do.....?

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top