The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to read a specific value from a Log file? cooolthud Shell Programming and Scripting 8 04-17-2008 08:30 AM
Post Shell programming: Question about source a file and read data from the file ccwq Shell Programming and Scripting 3 08-04-2007 07:28 PM
read specific text from a log file ragha81 Shell Programming and Scripting 4 10-17-2006 10:17 AM
How do you specific lines in a file? hedgehog001 UNIX for Dummies Questions & Answers 2 08-22-2005 09:04 PM
Shell Script to read specific lines in a file varshanswamy Shell Programming and Scripting 5 08-22-2005 04:12 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-28-2005
Registered User
 

Join Date: Sep 2005
Posts: 130
How to read specific lines in a bulk file using C file Programming

Please Help me

I have a Bulk file containing Hex data
I want to read specific lines from that bulk file by ID number.

example
ID DATE Time data
14 2005/09/28 07:40:08.546 0 5 078B1C 01916C 0FE59C 004B54 0A9670 0D04ED 05B6B4 0E2223 04B089 06AE50 000000 000000 000000

14 2005/09/28 07:42:27.765 0 5 078B1C 01916C 0A605E 08008A 04B85C 0D06D2 05B760 083222 045489 0CB190 000000 000000 000000

14 2005/09/28 07:44:41.274 0 5 078B1C 01916C 0FB19E 004B54 0A96AB 0D04ED 05B6B4 0E2223 04B089 06AE50 000000 000000 000000

suppose from that bulk file I want to read above Id 14 how it is possible.
by using c file programming.

please provide me code.


thanks
rajan
Reply With Quote
Forum Sponsor
  #2  
Old 09-28-2005
RishiPahuja's Avatar
Registered User
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Wink

Hi Rajan,

Where is the difficulty you are facing?
Is the bulk nature of file bogging you or is it only two days for weekend to come

rishi
Reply With Quote
  #3  
Old 09-28-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
You always have to read the whole file to find all records. This (minus error checking) is how to do it, by writing a simple filter:

Code:
#include <stdio.h>
void process_data(char *src)
{
     fprintf(stdout,"%s", src); /* do stuff with the data*/
}

int main()
{
    char tmp[256]={0x0};
    FILE *in=fopen"myfile","r");
    while(fgets(tmp,sizeof(tmp),in)!=NULL)
    {
         int testvalue=atoi(tmp);  /* atoi stops translating to an int
                                              when it hits a blank */
         if(test==14) process_data(tmp);
    }
    fclose(in);
    return 0;
}
Reply With Quote
  #4  
Old 09-29-2005
Registered User
 

Join Date: Sep 2005
Posts: 6
you can use "cspilt" shell command to do that
Reply With Quote
  #5  
Old 10-03-2005
Registered User
 

Join Date: Sep 2005
Posts: 130
Dear Friends,

The code you have given for Extractiong required data from file is working fine.
Thank u for your reply.
I have Extracted this data from file by using this code.

15711 2005/10/03 08:28:25.512 0 1 0B160E 06C67E 0A7F80 04C000 000000 000000 000000 000000 000000 000000 000000 000000 000000

15711 2005/10/03 08:29:57.517 0 1 0BE202 08C37E 007380 04A000 000000 000000 000000 000000 000000 000000 000000 000000 000000

15711 2005/10/03 08:31:29.502 0 1 0B9806 09C4DE 097800 048000 000000 000000 000000 000000 000000 000000 000000 000000 000000

15711 2005/10/03 08:33:01.507 0 1 0BDC0A 0BC5FE 0E7D00 04C000 000000 000000 000000 000000 000000 000000 000000 000000 000000

Now I wanted to write only the Hexadecimal data in separate file like this.

0B160E 06C67E 0A7F80 04C000 000000 000000 000000 000000 000000 000000 000000 000000 000000

from the above data simultaniously I have to leave starting 0 digit in each filed.and write into a separate file.

please provide C code for me

Iam ever thankful to you

regards

rajan


Reply With Quote
  #6  
Old 10-03-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,616
Please read our rules and note:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.

I will delete the thread where you post a second copy of this follow-up question.
Reply With Quote
  #7  
Old 10-04-2005
Registered User
 

Join Date: Sep 2005
Posts: 130
anybody please send reply to my post.

awiting for your replies

thank u

regards
rajan
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0