473,807 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I Remove lines above a key word, remove the lines below another, and keep the lines between the to key words in a Text File?

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

Example:

123123123123412 3423434
234123412341234 1242141
234512353764316 236234
123563532623512 5134534
Recipe
345353453532542 353245
523452354524564 26515
234523623874872 62346
326623562457245 72457
234623624526
End Recipe
436452346467
576474363473464 6
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!

Apr 20 '07 #1
2 2252
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.
Apr 20 '07 #2
On Apr 20, 11:00 am, "Duracel" <Dura...@nospam .comwrote:
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.readl ine
while line <Keyword1
output.writelin e(line)
end while

then what should I do.....?

Thank you!

Apr 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5034
by: Hans A | last post by:
I have a textfile "textfile.txt" containing a list of words. There is one word on each line. I want to pick two random lines from this textfile, and I have tried to do something like: //Loading the file into an array: $textarray = file("textfile.txt); //Using array_rand to pick two random words $rand_numbers = array_rand($textarray, 2);
5
1702
by: Manu | last post by:
Hi, Here's what i want to accomplish. I want to make a list of frequenctly occuring words in a group of files along with the no of occurances of each The brute force method will be to read the file as a string,split,load the words into a dict with words as key and no of occurances as key. Load the next file ,iterate through the new words increment the value if there is
3
4321
by: sahm | last post by:
does anyone know how to do it..i need help
9
37013
by: Ken | last post by:
I am trying to create one image using JavaScript; then later in the script remove the image - not just remove the src. The following creates the image, but I have been unable to remove it. How do I structure document.getElementById('num1').removeChild(image_display); ? <input type=file name="picture1" onChange="image(this.value, 'num1');" Id="pt1"> <div id='num1'></div>
18
23462
by: prasanna.hariharan | last post by:
Hi guys, I want to remove certain words from a c++ string. The list of words are in a file with each word in a new line. I tried using the std::transform, but it dint work. Anybody got a clue as to how i should go about this. thanks a lot, Hp
9
3191
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I want to be able to draw lines in a picturebox based upon certain data points I have received. I dragged a picturebox from the toolbar onto my form, but after having gone through the help files, looking online and trying a variety of things, I...
1
1688
by: Quentin | last post by:
First off, I would like to thank those who have given me help so far! I would like to remove all the lines of data above the word Recipe in a text file and all the lines below the words "End of Recipe" in this file. I want to keep everything inbetween these two lines. Below is a small sample of my text file and the code I have so far. 2,3,5,6,56,7,4,7,,,56,5,7, -1,45,4,451,7,66,7,667, "Recipe KX009.RCP, Date=02/11/07, Time=12:20:27,
9
13240
by: NvrBst | last post by:
Whats the best way to count the lines? I'm using the following code at the moment: public long GetNumberOfLines(string fileName) { int buffSize = 65536; int streamSize = 65536; long numOfLines = 0; byte bArr = new byte;
3
5280
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first add the pane the remove event does not get handled, though thereafter it is handled without problems. ==================================================
0
10372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10112
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3854
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.