1. HELP!!!
- Posted by Bryan Melugin <bmelugin at BELLSOUTH.NET> Jul 23, 1999
- 449 views
I'm new to Euphoria and have gone through the tutorial. My question will be easily answered by any one of you Euphoria Guru's out there. Here it goes. Can someone tell me how to pull information from a text file which includes only the information between two lines. Say I have a line that starts with ST and then there are 40 lines down and then there is a line that starts with SE. If I want just the info between ST and SE and put it into a different text file, can that be done? Any help would be greatly appreciated. I have been working on this for 3 days now and I've almost given up hope. Thanks again Bryan
2. Re: HELP!!!
- Posted by JJProg at CYBERBURY.NET Jul 23, 1999
- 430 views
EU>I'm new to Euphoria and have gone through the tutorial. My question EU>will be easily answered by any one of you Euphoria Guru's out there. EU>Here it goes. Can someone tell me how to pull information from a text EU>file which includes only the information between two lines. Say I have EU>a line that starts with ST and then there are 40 lines down and then EU>there is a line that starts with SE. If I want just the info between ST EU>and SE and put it into a different text file, can that be done? Any EU>help would be greatly appreciated. I have been working on this for 3 EU>days now and I've almost given up hope. EU>Thanks again EU>Bryan Try this: constant START = "ST\n" -- gets returns a new line character at the end -- of a line constant END = "SE\n" sequence line, data integer f f = open("infile.txt","r") line = gets(f) while not equal(line,START) do -- Skip all data before and including -- START line = gets(f) end while data = "" line = gets(f) while not equal(line,END) do -- Get all the data up to END data &= line line = gets(f) end while close(f) f = open("outfile.txt","w") puts(f,data) -- Write the data to the output file close(f) Jeffrey Fielding JJProg at cyberbury.net http://members.tripod.com/~JJProg/
3. Re: HELP!!!
- Posted by Bryan Melugin <bmelugin at BELLSOUTH.NET> Jul 23, 1999
- 439 views
Thanks for the Help! I tried that and it produced this error edi.ex:10 type_check failure, line is -1 Global & Local Variables edi.ex: line = -1 data = <no value> f = 3 Did I do something obviously wrong here? Bryan JJProg at CYBERBURY.NET wrote: > EU>I'm new to Euphoria and have gone through the tutorial. My question > EU>will be easily answered by any one of you Euphoria Guru's out there. > EU>Here it goes. Can someone tell me how to pull information from a text > EU>file which includes only the information between two lines. Say I have > EU>a line that starts with ST and then there are 40 lines down and then > EU>there is a line that starts with SE. If I want just the info between ST > EU>and SE and put it into a different text file, can that be done? Any > EU>help would be greatly appreciated. I have been working on this for 3 > EU>days now and I've almost given up hope. > EU>Thanks again > > EU>Bryan > > Try this: > > constant START = "ST\n" -- gets returns a new line character at the end > -- of a line > constant END = "SE\n" > sequence line, data > integer f > f = open("infile.txt","r") > line = gets(f) > while not equal(line,START) do -- Skip all data before and including > -- START > line = gets(f) > end while > data = "" > line = gets(f) > while not equal(line,END) do -- Get all the data up to END > data &= line > line = gets(f) > end while > close(f) > f = open("outfile.txt","w") > puts(f,data) -- Write the data to the output file > close(f) > > Jeffrey Fielding > JJProg at cyberbury.net > http://members.tripod.com/~JJProg/
4. Re: HELP!!!
- Posted by Bryan Melugin <bmelugin at BELLSOUTH.NET> Jul 23, 1999
- 450 views
By The Way, The Text file contains more than one record. There are 40 records in this file which means there are 40 ST and 40 SE all in the same file. Thats why I'm trying to pull them out into their own file. Bryan JJProg at CYBERBURY.NET wrote: > EU>I'm new to Euphoria and have gone through the tutorial. My question > EU>will be easily answered by any one of you Euphoria Guru's out there. > EU>Here it goes. Can someone tell me how to pull information from a text > EU>file which includes only the information between two lines. Say I have > EU>a line that starts with ST and then there are 40 lines down and then > EU>there is a line that starts with SE. If I want just the info between ST > EU>and SE and put it into a different text file, can that be done? Any > EU>help would be greatly appreciated. I have been working on this for 3 > EU>days now and I've almost given up hope. > EU>Thanks again > > EU>Bryan > > Try this: > > constant START = "ST\n" -- gets returns a new line character at the end > -- of a line > constant END = "SE\n" > sequence line, data > integer f > f = open("infile.txt","r") > line = gets(f) > while not equal(line,START) do -- Skip all data before and including > -- START > line = gets(f) > end while > data = "" > line = gets(f) > while not equal(line,END) do -- Get all the data up to END > data &= line > line = gets(f) > end while > close(f) > f = open("outfile.txt","w") > puts(f,data) -- Write the data to the output file > close(f) > > Jeffrey Fielding > JJProg at cyberbury.net > http://members.tripod.com/~JJProg/
5. Re: HELP!!!
- Posted by JJProg at CYBERBURY.NET Jul 23, 1999
- 441 views
EU>Thanks for the Help! EU>I tried that and it produced this error EU>edi.ex:10 EU>type_check failure, line is -1 EU>Global & Local Variables EU> edi.ex: EU> line = -1 EU> data = <no value> EU> f = 3 EU>Did I do something obviously wrong here? No. I didn't put in anything to handle an ecxception. EU>Bryan >By The Way, > The Text file contains more than one record. There are 40 records in this >file which means there are 40 ST and 40 SE all in the same file. Thats why >I'm trying to pull them out into their own file. Ok. How about this: >Bryan constant START = "ST\n" constant END = "SE\n" function GetRecord(integer f) object line -- In case it gets to the end of the file sequence data line = gets(f) while not equal(line,START) and sequence(line) do line = gets(f) end while if integer(line) then -- It got to the end of the file return -1 end if data = {} line = gets(f) while not equal(line,END) and sequence(line) do data &= line line = gets(f) end while return data end function Now just call GetRecord(f) for each record. Example: integer in, out, n object r in = open("infile.txt","r") n = 1 r = GetRecord(in) while r Just a sec. I'll finish this in another e-mail. Jeffrey Fielding JJProg at cyberbury.net http://members.tripod.com/~JJProg/
6. Re: HELP!!!
- Posted by JJProg at CYBERBURY.NET Jul 23, 1999
- 427 views
Now just call GetRecord(f) for each record. Example: integer in, out, n object r in = open("infile.txt","r") if in = -1 then puts(1,"Couldn't open infile.txt.\n") abort(1) end if n = 1 r = GetRecord(in) while sequence(r) do out = open(sprintf("out%d.txt",n),"w") if out = -1 then printf(1,"Couldn't open out%d.txt.\n",n) exit end if puts(out,r) close(out) n += 1 r = GetRecord(in) end while close(in) EU>Just a sec. I'll finish this in another e-mail. EU>Jeffrey Fielding EU>JJProg at cyberbury.net EU>http://members.tripod.com/~JJProg/