How to read specific lines in a bulk file using C file Programming


 
Thread Tools Search this Thread
Top Forums Programming How to read specific lines in a bulk file using C file Programming
# 1  
Old 09-28-2005
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
# 2  
Old 09-28-2005
Hammer & Screwdriver

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 Smilie

rishi
# 3  
Old 09-28-2005
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;
}

# 4  
Old 09-29-2005
you can use "cspilt" shell command to do that
# 5  
Old 10-03-2005
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


# 6  
Old 10-03-2005
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.
# 7  
Old 10-04-2005
anybody please send reply to my post.

awiting for your replies

thank u

regards
rajan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a new file from another file with lines begins with a specific string

Hi, I have a file with below format myfile.txt aa aa1 aa2 qq aa4 ghs aa6 bbc gdf I m looking to create a file where lines begins with aa. myfile1.txt aa aa1 aa2 (4 Replies)
Discussion started by: Litu1988
4 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

4. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

5. Shell Programming and Scripting

Read in specific lines in a file

I have a text file First title line name1 name2 name3 name4 (etc) other lines other lines other lines I want to read in this text file and parse the name1...name4 to a variable. How do I specificially read in these lines and these lines only? (10 Replies)
Discussion started by: piynik
10 Replies

6. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

7. Shell Programming and Scripting

Read from file specific place in file using inode

Hello, I am using tcsh on AIX. I would like to write a script that does the following: 1. given an inode, how do I find exactly the name of the file? I know I could do this using ls -i | grep <inode> but it returns: <inode> <filename>. I need some string manipulation or something to... (1 Reply)
Discussion started by: lastZenMaster
1 Replies

8. Shell Programming and Scripting

Post Shell programming: Question about source a file and read data from the file

This is shell programming assignment. It needs to create a file called .std_dbrc contains STD_DBROOT=${HOME}/class/2031/Assgn3/STD_DB (which includes all my simple database files) and I am gonna use this .std_dbrc in my script file (read the data from the database files) like this: .... (3 Replies)
Discussion started by: ccwq
3 Replies

9. Shell Programming and Scripting

Shell Script to read specific lines in a file

I have a file with contents as follows Record 1: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 5: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 6:... (5 Replies)
Discussion started by: varshanswamy
5 Replies

10. UNIX for Dummies Questions & Answers

To Read a text file using shell Programming

Hello! I need to read a text file containing certains rows and columns!The following is a sample file with only three rows! 01:41:30:00:05:51 OFF 48506649K 5769415 63494357K 01:41:30:00:05:65 ON 4493546K 27266552 5880264K 01:41:30:00:05:78 OFF 614556K 89121 47291K... (1 Reply)
Discussion started by: sandytul
1 Replies
Login or Register to Ask a Question