473,509 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parsing a text line vertically

3 New Member
Hi,
I have the problem of passing of more lines which I find really difficult, cause I am not experienced in C.

First Log file.
------------------------- Cat 1------ cat2-----------------
19.867: [Testdata 98095K->24545K(942080K), 0.1468955 secs]
19.845: [Testdata2 98095K->24545K(942080K), 0.1468955 secs]

I can pass it using
sscanf(line, "%*s %s %s %dK->%dK(%d%*s %d.%s %*s", &c, b, &r, &a, &o, &d, test)

but the second log file has the same information stored in the follwing way.

testdata
cat1 : 91.00 K
cat2 : 4.11 K

testdata2
cat1 : 911.00 K
cat2 : 24.11 K

I want to abstract cat1 and cat2 for every testdata.

But my problem is that I can only read a line at one time.

How can I save the position of file and give for every testdata: cat1 and cat2 simultaneously.

would appreciate anyy suggestions-
Aug 20 '07 #1
4 1263
mac11
256 Contributor
Hi,
I have the problem of passing of more lines which I find really difficult, cause I am not experienced in C.

First Log file.
------------------------- Cat 1------ cat2-----------------
19.867: [Testdata 98095K->24545K(942080K), 0.1468955 secs]
19.845: [Testdata2 98095K->24545K(942080K), 0.1468955 secs]

I can pass it using
sscanf(line, "%*s %s %s %dK->%dK(%d%*s %d.%s %*s", &c, b, &r, &a, &o, &d, test)

but the second log file has the same information stored in the follwing way.

testdata
cat1 : 91.00 K
cat2 : 4.11 K

testdata2
cat1 : 911.00 K
cat2 : 24.11 K

I want to abstract cat1 and cat2 for every testdata.

But my problem is that I can only read a line at one time.

How can I save the position of file and give for every testdata: cat1 and cat2 simultaneously.

would appreciate anyy suggestions-
I'd say to build a simple state machine to keep track of what testdata your working on - so, for example:
1. read a line
2. see if it's a blank line - if it is go back to #1
3. see if it's a "testdata" line - if it is stick it into some container, then go back to #1
4. if it's not a "testdata" line parse the line to get the "catx" and "xxxK" data
5. do whatever it is you do to associate the "testdata" entry you found in #3 with the "catx" and "xxxK" data sets you found in #4 (maybe you will store them up in an array somewhere, or maybe you just output them on the fly, whatever)
Aug 20 '07 #2
frank78
3 New Member
hi mac,
thank you for the fast reply.
but I am a newbie to c and don't know exactly how can i make a state machine mechanism.
is it like a case command in java? If then can you explain me or give a reference where i can look for it.
Aug 20 '07 #3
mac11
256 Contributor
hi mac,
thank you for the fast reply.
but I am a newbie to c and don't know exactly how can i make a state machine mechanism.
is it like a case command in java? If then can you explain me or give a reference where i can look for it.
A state machine is just whatever system you use to keep track of what you are doing in relation to what you have done before. The way I described it in the last post I imagined you would use something like this:

Expand|Select|Wrap|Line Numbers
  1. char current_line[512];
  2.  
  3. while( /* loop until your out of input */ )
  4. {
  5.     ... read a line from the log file into current_line ...
  6.  
  7.     if( /* current_line is a "textdata" */ )
  8.     {
  9.         /* starting a new set of entries, if you have a 
  10.          * collection place put textdata_line_holder
  11.          * and your cat data in there now - or just 
  12.          * output them or whatever */
  13.         ... code to do that ...
  14.  
  15.          /* you just copied off your textdata and cat data
  16.           * or output them or whatever - now clear out your
  17.           * temporary variables - (reset your state) */
  18.           ... code to clear temps ...
  19.  
  20.         /* now you've finished cleaning up you can start
  21.          * tracking the next entry - copy the line so you can
  22.          * collect or output it when you finish getting the 
  23.          * cat entries */     
  24.         strcpy( textdata_line_holder, current_line );
  25.     }
  26.     else if( /* current_line is a cat entry */ )
  27.     {
  28.         /* extract the cat data and put is somewhere
  29.          * so that you can get at it later */
  30.     }
  31.     else 
  32.     {
  33.         /* this is just extra - since the log file 
  34.          * only has textdata and cat lines this 
  35.          * must be a blank line - I don't think you 
  36.          * need to do anything here, but it's up to you */ 
  37.     }
  38. }
  39.  
The stuff above might not be exactly what you want but it should help. I just want to give you an idea of how to structure things, not a full-blown solution.
Aug 21 '07 #4
frank78
3 New Member
Thank you for the help.

A state machine is just whatever system you use to keep track of what you are doing in relation to what you have done before. The way I described it in the last post I imagined you would use something like this:

Expand|Select|Wrap|Line Numbers
  1. char current_line[512];
  2.  
  3. while( /* loop until your out of input */ )
  4. {
  5.     ... read a line from the log file into current_line ...
  6.  
  7.     if( /* current_line is a "textdata" */ )
  8.     {
  9.         /* starting a new set of entries, if you have a 
  10.          * collection place put textdata_line_holder
  11.          * and your cat data in there now - or just 
  12.          * output them or whatever */
  13.         ... code to do that ...
  14.  
  15.          /* you just copied off your textdata and cat data
  16.           * or output them or whatever - now clear out your
  17.           * temporary variables - (reset your state) */
  18.           ... code to clear temps ...
  19.  
  20.         /* now you've finished cleaning up you can start
  21.          * tracking the next entry - copy the line so you can
  22.          * collect or output it when you finish getting the 
  23.          * cat entries */     
  24.         strcpy( textdata_line_holder, current_line );
  25.     }
  26.     else if( /* current_line is a cat entry */ )
  27.     {
  28.         /* extract the cat data and put is somewhere
  29.          * so that you can get at it later */
  30.     }
  31.     else 
  32.     {
  33.         /* this is just extra - since the log file 
  34.          * only has textdata and cat lines this 
  35.          * must be a blank line - I don't think you 
  36.          * need to do anything here, but it's up to you */ 
  37.     }
  38. }
  39.  
The stuff above might not be exactly what you want but it should help. I just want to give you an idea of how to structure things, not a full-blown solution.
Aug 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1859
by: Al Christians | last post by:
I've got an idea for an application, and I wonder how much of what it takes to create it is available in open source python components. My plan is this -- I want to do a simple spreadsheet-like...
16
2856
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
5
1848
by: Wilhelm Kutting | last post by:
Hi i want to use the following layout: ----------------- | | | | Text line 1 | | | Text line 2 | image.jpg | | ... | | | | | |
3
2445
by: ghadley_00 | last post by:
Hi, I have a MS access database into which I need to import a text file that is oriented vertically (fields are listed from top to bottom with the value for each field appearing to the right of...
18
2143
by: ILCSP | last post by:
Hi, I just started learning Visual Basic (VB.NET 03) and I need to do this small program that will read a text file we get from another company that has survey data, parse it and flatten it out and...
4
4421
by: avi | last post by:
Hello, I am trying to vertically center text in a background image, I found a solution on this site that sets the line-height to the height of the background image. This works just fine, except...
3
1472
by: Looch | last post by:
Hi All, Not sure if parsing is the correct word but here is what I'm trying to do: I have a method that returns a dataset that uses a select statement that comprises three union all'd select...
2
2578
by: python | last post by:
I'm parsing a text file for a proprietary product that has the following 2 directives: #include <somefile> #define <name<value> Defined constants are referenced via <#name#syntax. I'm...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
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...
0
5656
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,...
1
5062
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...
0
4732
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...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.