Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > parsing text

Reply
Thread Tools

parsing text

 
 
yang__lee@ausi.com
Guest
Posts: n/a
 
      04-11-2007
Hi,

I hope you may help me.

Please check the attached text file.
Actually its a report file with some headers information
and them report is in tabular format. I want to parse each row
and get the values.

I think strtok won't work here.

There are no tabs in between the column values they are spaces.
Column values them selves contain spaces but they are single spaces.
Minimum two spaces are there between column values.

can you suggest some algorithm in C or any other method to get each
column value.

In excel I try to create a delimited file but its unsuccessful.

Thanks,

lee


following content is in a text file. Copy in a text file
Keep wordwrap off
-------------------------------------------------------------------------------




DATE: 04/07/2007

TMK

MTC_PROC REPORT

Area: KTO
WRKPCK: KTO


PROCESS PNAME FEANAME CEB MCO DPNUM NM_ITM
ERROR
TXT_GUI ERROID
_______ ___________ _____________ ___ ___ ______ __________
________________________________________________
__________________________________________________ __________ ______

RECKKON 206 DEVICE 007 997 532533 532533
Invalid source. BREAK needed. Count: 1501-1505
Source: -98 0201

RECKKON U206 DEVICE 007 997 532533 532533
Invalid source. BREAK needed. Count:
1421,1726-1730 Source: -98 0201

RECKKON F77 CROSS CNNCT 009 997 520624 520624
Feeder feature. Count: AM992,651-900
Source: 520619 7310

RECKKON F1727 X-MIC 009 997 521184 521184
Sourced Out. Count: SA5211,1-1800
Source: 0 0206

RECKKON F115 CROSS CNNCT 009 997 522306 522306
provide feed. Count:
1400,1001-1100 Source: 522333 7310

 
Reply With Quote
 
 
 
 
mark_bluemel@pobox.com
Guest
Posts: n/a
 
      04-11-2007
On 11 Apr, 11:44, (E-Mail Removed) wrote:
> Hi,
>
> I hope you may help me.
>
> Please check the attached text file.
> Actually its a report file with some headers information
> and them report is in tabular format. I want to parse each row
> and get the values.
>
> I think strtok won't work here.
>
> There are no tabs in between the column values they are spaces.
> Column values them selves contain spaces but they are single spaces.
> Minimum two spaces are there between column values.
>
> can you suggest some algorithm in C or any other method to get each
> column value.


You know what data is in what character positions, so what's wrong
with extracting the data on that basis?

strncpy() would do for starters. More complex code could wrap this to
strip trailing spaces, convert to numeric format, etc...

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      04-11-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I hope you may help me.
>
> Please check the attached text file.


No, thank you. Do not post attachments to text newsgroups.
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      04-11-2007
In article <(E-Mail Removed)>,
Martin Ambuhl <(E-Mail Removed)> wrote:

>> Please check the attached text file.


>No, thank you. Do not post attachments to text newsgroups.


In fact he didn't post an attachment. He just appended the text to
his message.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      04-11-2007
Richard Tobin wrote:
> In article <(E-Mail Removed)>,
> Martin Ambuhl <(E-Mail Removed)> wrote:
>
>>> Please check the attached text file.

>
>> No, thank you. Do not post attachments to text newsgroups.

>
> In fact he didn't post an attachment. He just appended the text to
> his message.


As silly as it may be, I tend to believe posters unless this has already
been shown to be an error. At the point that (E-Mail Removed) (an
attribution you unaccountably removed) wrote that there was an attached
file, there was no reason to doubt his word. Silly me.

In the same way, if I encountered your post without known earlier
context, I might think that I had written
>>> Please check the attached text file.

I would wonder when I did it, and why there were extra '>'s, but you
claimed that I wrote, so I must have.
 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      04-11-2007
You have two formats, one for the header and one for the body.

Write a function to parse the header and another function to parse the
body.

Do not write one function to do both jobs. It is also easy to
recognize the transition between header and body so write a
controlling function that sees the header and calls the header parser
and then sees the body and calls the body parser.

Your question is really more appropriate for news:comp.programming
since you do not have a C question but a programming one.

Personally, I would parse the header and then throw the body into a
text file and use an ODBC text file connection. But that's neither
here nor there and it's not even topical on news:comp.lang.c

bcnu

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      04-11-2007
In article <(E-Mail Removed)>,
Martin Ambuhl <(E-Mail Removed)> wrote:

>>>> Please check the attached text file.


>>> No, thank you. Do not post attachments to text newsgroups.


>> In fact he didn't post an attachment. He just appended the text to
>> his message.


>As silly as it may be, I tend to believe posters unless this has already
>been shown to be an error. At the point that (E-Mail Removed) (an
>attribution you unaccountably removed) wrote that there was an attached
>file, there was no reason to doubt his word. Silly me.


"Attached" doesn't only mean "MIME attachment". The phrase "the
attached X" has been around for a long time.

>In the same way, if I encountered your post without known earlier
>context, I might think that I had written
> >>> Please check the attached text file.

>I would wonder when I did it, and why there were extra '>'s, but you
>claimed that I wrote, so I must have.


When you become familiar with Usenet quoting conventions, you will not
have this problem.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      04-11-2007
Richard Tobin wrote:
> In article <(E-Mail Removed)>,
> Martin Ambuhl <(E-Mail Removed)> wrote:


>> In the same way, if I encountered your post without known earlier
>> context, I might think that I had written
>>>>> Please check the attached text file.

>> I would wonder when I did it, and why there were extra '>'s, but you
>> claimed that I wrote, so I must have.

>
> When you become familiar with Usenet quoting conventions, you will not
> have this problem.


When you become familiar with Usenet quoting conventions, you will no
longer snip attributions aways from text your are quoting. Your
practice is at least cavalier and sloppy; it is possibly dishonest as well.
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      04-11-2007
Richard Tobin wrote:
>
> When you become familiar with Usenet quoting conventions, you will not
> have this problem.
>

Your conventions, or everyone else's?

--
Ian Collins.
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      04-11-2007
user923005 wrote:

> You have two formats, one for the header and one for the body.


I do?

> Write a function to parse the header and another function to parse the
> body.


Why would I want to do that?

> Do not write one function to do both jobs. It is also easy to
> recognize the transition between header and body so write a
> controlling function that sees the header and calls the header parser
> and then sees the body and calls the body parser.


If you say so!

> Your question is really more appropriate for news:comp.programming
> since you do not have a C question but a programming one.


I didn't know I had a question.

> Personally, I would parse the header and then throw the body into a
> text file and use an ODBC text file connection. But that's neither
> here nor there and it's not even topical on news:comp.lang.c


You're the one who brought it up.


Unless, perhaps, this was meant as a reply to some OTHER person. As
there's no quotes are attributions, that's rank speculation on my part.




Brian
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SAX parsing problem, when element contains text like "[text]" Kai Schlamp Java 1 03-27-2008 08:36 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
Assistance parsing text file using Text::CSV_XS Domenico Discepola Perl Misc 6 09-02-2004 03:55 PM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments