Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:24:56+00:00 2026-06-18T08:24:56+00:00

I want to process a log file(using C) in which the data are separated

  • 0

I want to process a log file(using C) in which the data are separated by double colons “::”. I suppose tools like awk and sed will be quite efficient to do this. But is it possible that awk output values can pass to my C variable?
For example, one log info is like this:

a::b::c::d  

and I have a struct consists of 4 int elements. How to save the 4 parts into the struct elements?
I’ve thought of using strtok libary call as another way, but before calling it, I have to sort out the suitable lines from a whole bunch of log information, and that makes me think more about the sed or grep.
Thank you for your help. If you have better choices, that will be very kind of you to share it.

update: I forgot to emphasize that everything mentioned above is done in runtime including “sort out the matched lines according to a given value”, and process them, then store the value. scanf is fine, but what if there is string value with spaces inside?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:24:57+00:00Added an answer on June 18, 2026 at 8:24 am

    You can always use a mixture of tools. For example, let’s say your log file is in the file log.out.

    Then you can use grep to select the lines you are interested in:

    grep "^-\?[0-9]\+::-\?[0-9]\+::-\?[0-9]\+::-\?[0-9]\+$" log.out
    

    You could either store it as another file, or directly give it to your program:

    grep ... | ./analyze_data
    

    Assuming your program is named analyze_data. In the source of the program, you simply read from stdin and store the values you want:

    scanf("%d::%d::%d::%d", &a, &b, &c, &d);
    

    Of course with proper error checking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single big text file in which I want to process each
Say I have a data file that I want to process; I want to
I have a Mason template running under mod_perl, which is using Log::Log4perl. I want
I want to process MSXML which is generated by Visio 2010, Which Language will
I want to process a medium to large number of text snippets using a
I want to process a request header using a custom rewrite map. Therefore I
I want to process a file line by line in c, all lines in
I have a pool of worker processes (using multiprocessing.Pool ) and want to log
I have a small python script which invokes an external process using subprocess .
I want to open file for append on Windows 7 host using C#/.NET. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.