473,585 Members | 2,512 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 1268
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
1862
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 application: I've used a wxGrid, so I expect that wxPython will do fine for the user interface. The spreadsheet can be organized vertically, one...
16
2875
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 loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after...
5
1853
by: Wilhelm Kutting | last post by:
Hi i want to use the following layout: ----------------- | | | | Text line 1 | | | Text line 2 | image.jpg | | ... | | | | | |
3
2457
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 the field name (with a "|" as a delimiter)). The text file will only have 1 record's data. I would ideally like to setup a linked table to import...
18
2156
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 make single strings out of the records in it. The major difference between this space delimited file from the many examples in these groups is...
4
4434
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 when the text is too long that it wraps. div.module h2{ width:178px; width:"182px"; height:28px; font-family:"Avenir Black", verdana, geneva,...
3
1476
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 statements (i.e. "select author from table1 union all select author from table 2..."). The end result is a small dataset with one column and four...
2
2581
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 looking for a single text stream that results from processing a file containing these directives. Even better would be an iterator(?) type
0
7908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
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...
1
7950
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...
0
8212
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...
0
6606
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...
1
5710
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...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1175
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...

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.