Sponsored Content
Full Discussion: File reading in C
Top Forums Programming File reading in C Post 302405280 by jim mcnamara on Thursday 18th of March 2010 10:35:02 AM
Old 03-18-2010
You want "@" to be the delimiter. Nothing else.
When you get "Message Id" the second string is your value.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* non-destructive strtok() */

char **
split( char *result[], char *src, const char *delim)
{
          static char working[1024]={0x0};
          int i=0;
          char *p=NULL;

          result[0]=NULL;
          strcpy(working, src);
          for(i=0, p=strtok(working, delim); p!=NULL; p=strtok(NULL, delim), i++ )
          {
                 result[i]=p;
                 result[i+1]=NULL;
          }
          return result;
}

int main()
{
	 char *p[40]={NULL};  /* allow for 40 @ chars in a line */
	 char tmp[256]={0x0};
	 int i=0;
	 FILE *in=fopen("somefile", "r");
	 
	 while( fgets(tmp, sizeof(tmp), in)!=NULL)
	 {
	 		split(p, tmp, "@");
	 		for(i=0; p[i]!=NULL; i++)
	 		{
	 			if(!strcmp(p[i], "Message Id")  )
	 		   	printf("my value==:%s\n", p[i+1]);
	 		}
	 			   
	 }
	 fclose(in);
	 
   return 0;
}

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies

2. UNIX for Advanced & Expert Users

Reading a file and sending mail based on content of the file

Hi Gurus, I am having an requirement. i have to read a list file which contains file names and send mail to different users based on the files in the list file. eg. if file a.txt exists then send a mail to a@a.com simillary for b.txt,c.txt etc. Thanks for your help, Nimu (6 Replies)
Discussion started by: nimu1979
6 Replies

3. UNIX for Dummies Questions & Answers

Reading from a file(passing the file as input parameter)

hi I have a shell script say primary.sh . There is a file called params my scenario is primary.sh should read all the values and echo it for example i should pass like $primary.sh params output would be Abc ... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

4. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

5. Shell Programming and Scripting

fatal: cannot open file `TNAME' for reading (No such file or directory)

Hi, I am running this command through a shell script and getting the error mentioned in the subject line: testing.awk -f x.txt TNAME My testing.awk file contains something like ++++++++++++++++++ #!/usr/bin/awk -f BEGIN{ TAB_NAME="INSERT_ONE_" ARGV ; } if ( $1=="JAM_ONE" &&... (1 Reply)
Discussion started by: kunwar
1 Replies

6. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

7. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

8. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

9. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies
STRING(3)						   BSD Library Functions Manual 						 STRING(3)

NAME
stpcpy, stpncpy, strcat, strlcat, strncat, strchr, strrchr, strcmp, strncmp, strcasecmp, strncasecmp, strcoll, strcpy, strlcpy, strncpy, strerror, strerror_r, strlen, strnlen, strpbrk, strsep, stresep, strspn, strcspn, strdup, strndup, strstr, strcasestr, strtok, strtok_r, strxfrm -- string specific functions LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * stpcpy(char *dst, const char *src); char * stpncpy(char *dst, const char *src, size_t count); char * strcat(char *s, const char * append); size_t strlcat(char *dst, const char *src, size_t size); char * strncat(char *s, const char *append, size_t count); char * strchr(const char *s, int c); char * strrchr(const char *s, int c); int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t count); int strcasecmp(const char *s1, const char *s2); int strncasecmp(const char *s1, const char *s2, size_t count); int strcoll(const char *s1, const char *s2); char * strcpy(char *dst, const char *src); size_t strlcpy(char *dst, const char *src, size_t size); char * strncpy(char *dst, const char *src, size_t count); char * strerror(int errno); int strerror_r(int errnum, char *strerrbuf, size_t buflen); size_t strlen(const char *s); size_t strnlen(const char *s, size_t count); char * strpbrk(const char *s, const char *charset); char * strsep(char **stringp, const char *delim); char * stresep(char **stringp, const char *delim, int escape); size_t strspn(const char *s, const char *charset); size_t strcspn(const char *s, const char *charset); char * strdup(const char *str); char * strndup(const char *str, size_t len); char * strstr(const char *big, const char *little); char * strcasestr(const char *big, const char *little); char * strtok(char *s, const char *delim); char * strtok_r(char *s, const char *delim, char **lasts); size_t strxfrm(char *dst, const char *src, size_t n); DESCRIPTION
The string functions manipulate strings terminated by a nul byte. See the specific manual pages for more information. For manipulating variable length generic objects as byte strings (without the nul byte check), see bstring(3). Except as noted in their specific manual pages, the string functions do not test the destination for size limitations. SEE ALSO
bstring(3), strcat(3), strchr(3), strcmp(3), strcoll(3), strcpy(3), strcspn(3), strdup(3), strerror(3), strings(3), strlcat(3), strlen(3), strpbrk(3), strrchr(3), strsep(3), strspn(3), strstr(3), strtok(3), strxfrm(3) STANDARDS
The strcat(), strncat(), strchr(), strrchr(), strcmp(), strncmp(), strcpy(), strncpy(), strcoll(), strerror(), strlen(), strpbrk(), strsep(), strspn(), strcspn(), strstr(), strtok(), and strxfrm() functions conform to ANSI X3.159-1989 (``ANSI C89''). The strtok_r() function conforms to IEEE Std 1003.1c-1995 (``POSIX.1''). The strerror_r() function conform to IEEE Std 1003.1-2001 (``POSIX.1''). BSD
May 1, 2009 BSD
All times are GMT -4. The time now is 04:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy