extract all hotmail email addresses in a file and store in separatefile

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis

    #1

    extract all hotmail email addresses in a file and store in separatefile

    Hi, I have a text file that contents a list of email addresses like
    this:

    "foo@yahoo. com"
    "tom@hotmail.co m"
    "jerry@gmail.co m"
    "tommy@apple.co m"

    I like to

    1. Strip out the " characters and just leave the email addresses on
    each line.
    2. extract out the hotmail addresses and store it into another file.
    The hotmail addresses in the original file would be deleted.

    Thanks for any help
  • cartercc

    #2
    Re: extract all hotmail email addresses in a file and store inseparate file

    On Jun 18, 3:33 pm, Dennis <dcho...@gmail. comwrote:
    Hi, I have a text file that contents a list of email addresses like
    this:
    >
    "f...@yahoo.com "
    "t...@hotmail.c om"
    "je...@gmail.co m"
    "to...@apple.co m"
    >
    I like to
    >
    1. Strip out the " characters and just leave the email addresses on
    each line.
    2. extract out the hotmail addresses and store it into another file.
    The hotmail addresses in the original file would be deleted.
    >
    Thanks for any help
    open INFILE, "<all_emails.tx t";
    open HOTMAIL, ">hotmail_only. txt";
    open NOTHOTMAIL, ">not_hotmail.t xt";
    while(<INFILE>)
    {
    $_ =~ s/"//g;
    print HOTMAIL if $_ =~ /hotmail/i;
    print NOTHOTMAIL if $_ != /hotmail/i;
    }
    close INFILE;
    close HOTMAIL;
    close NOTHOTMAIL;

    Comment

    • cartercc

      #3
      Re: extract all hotmail email addresses in a file and store inseparate file

      On Jun 18, 3:33 pm, Dennis <dcho...@gmail. comwrote:
      Hi, I have a text file that contents a list of email addresses like
      this:
      >
      "f...@yahoo.com "
      "t...@hotmail.c om"
      "je...@gmail.co m"
      "to...@apple.co m"
      >
      I like to
      >
      1. Strip out the " characters and just leave the email addresses on
      each line.
      2. extract out the hotmail addresses and store it into another file.
      The hotmail addresses in the original file would be deleted.
      >
      Thanks for any help
      open INFILE, "<all_emails.tx t";
      open HOTMAIL, ">hotmail_only. txt";
      open NOTHOTMAIL, ">not_hotmail.t xt";
      while(<INFILE>)
      {
      $_ =~ s/"//g;
      print HOTMAIL if $_ =~ /hotmail/i;
      print NOTHOTMAIL if $_ != /hotmail/i;
      }
      close INFILE;
      close HOTMAIL;
      close NOTHOTMAIL;

      Comment

      • szr

        #4
        Re: extract all hotmail email addresses in a file and store in separate file

        Dennis wrote:
        Hi, I have a text file that contents a list of email addresses like
        this:
        >
        "foo@yahoo. com"
        "tom@hotmail.co m"
        "jerry@gmail.co m"
        "tommy@apple.co m"
        >
        I like to
        >
        1. Strip out the " characters and just leave the email addresses on
        each line.
        2. extract out the hotmail addresses and store it into another file.
        The hotmail addresses in the original file would be deleted.
        >
        Thanks for any help
        To get you started, assuming there are no escaped quotes in between:

        while (m!"([^"]+?)"!g) {
        if ($1 =~ m!\@hotmail\.co m!) {
        ... do something with $1
        }
        else { ... }
        }


        Or if you are using an array:

        foreach my $email (map { s!"([^"]+?)"!$1!g; $_; } @email_list) {
        if ($email =~ m!\@hotmail\.co m!) {
        ...
        }
        else { ... }
        }

        (Note, untested, but should give a starting point.)

        --
        szr


        Comment

        • Antoninus Twink

          #5
          Re: extract all hotmail email addresses in a file and store inseparate file

          On 18 Jun 2008 at 20:01, cartercc wrote:
          On Jun 18, 3:33 pm, Dennis <dcho...@gmail. comwrote:
          >I like to
          >>
          >1. Strip out the " characters and just leave the email addresses on
          >each line.
          >2. extract out the hotmail addresses and store it into another file.
          >The hotmail addresses in the original file would be deleted.
          >
          open INFILE, "<all_emails.tx t";
          open HOTMAIL, ">hotmail_only. txt";
          open NOTHOTMAIL, ">not_hotmail.t xt";
          while(<INFILE>)
          {
          $_ =~ s/"//g;
          print HOTMAIL if $_ =~ /hotmail/i;
          print NOTHOTMAIL if $_ != /hotmail/i;
          }
          close INFILE;
          close HOTMAIL;
          close NOTHOTMAIL;
          Firstly, you mean !~ instead of !=. Secondly, referring to $_ all the
          time is unnecessary. Try:

          open INFILE, "< all_emails.txt" ;
          open HOTMAIL, "hotmail_only.t xt";
          open NOTHOTMAIL, "not_hotmail.tx t";
          while(<INFILE>)
          {
          s/"//g;
          if (/hotmail/i) {
          print HOTMAIL;
          } else {
          print NOTHOTMAIL;
          }
          }
          close INFILE;
          close HOTMAIL;
          close NOTHOTMAIL;

          You might also like to include some error-checking, and avoid
          hard-coding the paths.

          Comment

          • Bartc

            #6
            Re: extract all hotmail email addresses in a file and store in separate file


            "Dennis" <dchou4u@gmail. comwrote in message
            news:e4359263-995d-4b1a-8865-9a97eceb7dc2@m3 6g2000hse.googl egroups.com...
            Hi, I have a text file that contents a list of email addresses like
            this:
            >
            "foo@yahoo. com"
            "tom@hotmail.co m"
            "jerry@gmail.co m"
            "tommy@apple.co m"
            >
            I like to
            >
            1. Strip out the " characters and just leave the email addresses on
            each line.
            2. extract out the hotmail addresses and store it into another file.
            The hotmail addresses in the original file would be deleted.
            You have perl solutions so you won't need this. But was an interesting
            little snippet:

            /* Sort email addresses (possibly for some nefarious purpose) from file
            "input" */
            #include <stdio.h>
            #include <stdlib.h>
            #include <string.h>

            void error(void) {puts("File error"); exit(0);}

            int main(void) {
            char line[200];
            char *p;
            int n;

            FILE *in,*hot,*notho t;

            in=fopen("input ","r");
            if (in==0) error();

            hot=fopen("hotm ail","w");
            if (hot==0) {fclose(in); error();};

            nothot=fopen("n othotmail","w") ;
            if (nothot==0) {fclose(in); fclose(nothot); error();};

            while (1) {

            fgets(line,size of(line),in);
            if (feof(in)) break;

            n=strlen(line);
            p=line;
            if (line[n-1]='\n') {line[n-1]=0; --n;};
            if (n) {
            if (line[n-1]='""') {line[n-1]=0; --n;};
            if (*p=='"') ++p;

            if (strstr(p,"@hot mail.com"))
            fprintf(hot,"%s \n",p);
            else
            fprintf(nothot, "%s\n",p);
            };
            };

            fclose(in);
            fclose(hot);
            fclose(nothot);

            }


            --
            Bartc


            Comment

            • Rui Maciel

              #7
              Re: extract all hotmail email addresses in a file and store inseparatefile

              On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:
              Hi, I have a
              <snip />

              Why are you cross-posting this to C and Perl newsgroups?


              Rui Maciel

              Comment

              • Kenny McCormack

                #8
                Re: extract all hotmail email addresses in a file and store inseparatefile

                In article <485975dc$0$250 52$a729d347@new s.telepac.pt>,
                Rui Maciel <rui.maciel@gma il.comwrote:
                >On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:
                >
                >Hi, I have a
                ><snip />
                >
                >Why are you cross-posting this to C and Perl newsgroups?
                >
                >
                >Rui Maciel
                I assume because he is interested in a C/Perl solution to his problem.

                Comment

                • =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?=

                  #9
                  Re: extract all hotmail email addresses in a file and store inseparate file

                  On Jun 18, 8:33 pm, Dennis <dcho...@gmail. comwrote:
                  1. Strip out the " characters and just leave the email addresses on
                  each line.
                  char const *const original = "\"bob@hotmail. com\"";

                  char buf[50];

                  strcpy(buf,orig inal);

                  buf[strlen(original ) - 1] = 0;

                  2. extract out the hotmail addresses and store it into another file.

                  Take the last 12 characters, make them all lowercase, and then compare
                  with "@hotmail.c om".

                  I'm not big up on the file access functions, I usually just consult
                  the reference at dinkumware.com when I want to use them.

                  Comment

                  • Jürgen Exner

                    #10
                    Re: extract all hotmail email addresses in a file and store in separate file

                    Dennis <dchou4u@gmail. comwrote:
                    >Hi, I have a text file that contents a list of email addresses like
                    >this:
                    >
                    >"foo@yahoo.com "
                    >"tom@hotmail.c om"
                    >"jerry@gmail.c om"
                    >"tommy@apple.c om"
                    >
                    >I like to
                    >
                    >1. Strip out the " characters and just leave the email addresses on
                    >each line.
                    'perldoc perlop' and look for either tr/// in combination with the 'd'
                    option or s/// in combination with the 'g' option. Maybe in combination
                    with anchoring the RE.

                    Or you can use substr() to grab anything between the first and last
                    character, excluding both.
                    >2. extract out the hotmail addresses
                    perldoc -f grep
                    >and store it into another file.
                    perldoc -f open
                    >The hotmail addresses in the original file would be deleted.
                    perldoc -q "delete a line"

                    jue

                    Comment

                    • pete

                      #11
                      Re: extract all hotmail email addresses in a file and store in separatefile

                      Dennis wrote:
                      Hi, I have a text file that contents a list of email addresses like
                      this:
                      >
                      "foo@yahoo. com"
                      "tom@hotmail.co m"
                      "jerry@gmail.co m"
                      "tommy@apple.co m"
                      >
                      I like to
                      >
                      1. Strip out the " characters and just leave the email addresses on
                      each line.
                      2. extract out the hotmail addresses and store it into another file.
                      The hotmail addresses in the original file would be deleted.
                      >
                      Thanks for any help
                      /* BEGIN new.c output */

                      Original original file contents:
                      "foo@yahoo. com"
                      "tom@hotmail.co m"
                      "jerry@gmail.co m"
                      "tommy@apple.co m"

                      Final original file contents:
                      foo@yahoo.com
                      jerry@gmail.com
                      tommy@apple.com

                      Final other file contents:
                      tom@hotmail.com

                      /* END new.c output */

                      /* BEGIN new.c */

                      #include <stdio.h>
                      #include <stdlib.h>
                      #include <string.h>
                      #include <limits.h>

                      #define STRINGS \
                      { "\"foo@yahoo.co m\"", "\"tom@hotmail. com\"", \
                      "\"jerry@gmail. com\"", "\"tommy@apple. com\""}

                      struct list_node {
                      struct list_node *next;
                      void *data;
                      };

                      typedef struct list_node list_type;

                      void squeeze(char *s1, const int s2);
                      int get_line(char **lineptr, size_t *n, FILE *stream);
                      int list_fputs(cons t list_type *node, FILE *stream);
                      list_type *list_append
                      (list_type **head, list_type *tail, void *data, size_t size);
                      void list_free(list_ type *node, void (*free_data)(vo id *));

                      int main (void)
                      {
                      int rc;
                      size_t n;
                      char fn[2][L_tmpnam];
                      FILE *fp[2];
                      char *string[] = STRINGS;
                      size_t size = 0;
                      char *buff = NULL;
                      list_type *head = NULL;
                      list_type *tail = NULL;

                      puts("/* BEGIN new.c output */\n");
                      /*
                      ** Create input file
                      */
                      tmpnam(fn[0]);
                      tmpnam(fn[1]);
                      fp[0] = fopen(fn[0], "w");
                      if (fp[0] == NULL) {
                      fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
                      exit(EXIT_FAILU RE);
                      }
                      for (n = 0; n != sizeof string / sizeof *string; ++n) {
                      fprintf(fp[0], "%s\n", string[n]);
                      }
                      fclose(fp[0]);
                      /*
                      ** Read input file into list
                      */
                      fp[0] = fopen(fn[0], "r");
                      if (fp[0] == NULL) {
                      fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
                      exit(EXIT_FAILU RE);
                      }
                      while ((rc = get_line(&buff, &size, fp[0])) 0) {
                      tail = list_append(&he ad, tail, buff, rc);
                      if (tail == NULL) {
                      fputs("tail == NULL\n", stderr);
                      break;
                      }
                      }
                      fclose(fp[0]);
                      /*
                      ** Display input file contents
                      */
                      puts("Original original file contents:");
                      list_fputs(head , stdout);
                      putchar('\n');
                      /*
                      ** Strip out quotes from strings in memory
                      */
                      for (tail = head; tail != NULL; tail = tail -next) {
                      squeeze(tail -data, '"');
                      }
                      /*
                      ** Create output files
                      */
                      fp[0] = fopen(fn[0], "w");
                      if (fp[0] == NULL) {
                      fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
                      exit(EXIT_FAILU RE);
                      }
                      fp[1] = fopen(fn[1], "w");
                      if (fp[1] == NULL) {
                      remove(fn[0]);
                      fputs("fopen(fn[1]), \"w\") == NULL\n", stderr);
                      exit(EXIT_FAILU RE);
                      }
                      for (tail = head; tail != NULL; tail = tail -next) {
                      if (strstr(tail -data, "hotmail") == NULL) {
                      fprintf(fp[0], "%s\n", tail -data);
                      } else {
                      fprintf(fp[1], "%s\n", tail -data);
                      }
                      }
                      list_free(head, free);
                      tail = head = NULL;
                      fclose(fp[0]);
                      fclose(fp[1]);
                      /*
                      ** Read original file
                      ** Display original file contents
                      */
                      fp[0] = fopen(fn[0], "r");
                      if (fp[0] == NULL) {
                      fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
                      exit(EXIT_FAILU RE);
                      }
                      puts("Final original file contents:");
                      while ((rc = get_line(&buff, &size, fp[0])) 0) {
                      puts(buff);
                      }
                      putchar('\n');
                      fclose(fp[0]);
                      /*
                      ** Read other file
                      ** Display other file contents
                      */
                      fp[1] = fopen(fn[1], "r");
                      if (fp[1] == NULL) {
                      fputs("fopen(fn[1], \"r\") == NULL\n", stderr);
                      exit(EXIT_FAILU RE);
                      }
                      puts("Final other file contents:");
                      while ((rc = get_line(&buff, &size, fp[1])) 0) {
                      puts(buff);
                      }
                      putchar('\n');
                      free(buff);
                      buff = NULL;
                      size = 0;
                      fclose(fp[1]);
                      remove(fn[0]);
                      remove(fn[1]);
                      puts("/* END new.c output */");
                      return 0;
                      }

                      void squeeze(char *s1, const int c)
                      {
                      char *p;

                      for (p = s1; *s1 != '\0'; ++s1) {
                      if (c != *s1) {
                      *p++ = *s1;
                      }
                      }
                      *p = '\0';
                      }

                      int get_line(char **lineptr, size_t *n, FILE *stream)
                      {
                      int rc;
                      void *p;
                      size_t count;
                      /*
                      ** The (char) casts in this function are not required
                      ** by the rules of the C programming language.
                      */
                      count = 0;
                      while ((rc = getc(stream)) != EOF
                      || !feof(stream) && !ferror(stream) )
                      {
                      ++count;
                      if (count == (size_t)-2) {
                      if (rc != '\n') {
                      (*lineptr)[count] = '\0';
                      (*lineptr)[count - 1] = (char)rc;
                      } else {
                      (*lineptr)[count - 1] = '\0';
                      }
                      break;
                      }
                      if (count + 2 *n) {
                      p = realloc(*linept r, count + 2);
                      if (p == NULL) {
                      if (*n count) {
                      if (rc != '\n') {
                      (*lineptr)[count] = '\0';
                      (*lineptr)[count - 1] = (char)rc;
                      } else {
                      (*lineptr)[count - 1] = '\0';
                      }
                      } else {
                      if (*n != 0) {
                      **lineptr = '\0';
                      }
                      ungetc(rc, stream);
                      }
                      count = 0;
                      break;
                      }
                      *lineptr = p;
                      *n = count + 2;
                      }
                      if (rc != '\n') {
                      (*lineptr)[count - 1] = (char)rc;
                      } else {
                      (*lineptr)[count - 1] = '\0';
                      break;
                      }
                      }
                      if (rc != EOF || !feof(stream) && !ferror(stream) ) {
                      rc = INT_MAX count ? count : INT_MAX;
                      } else {
                      if (*n count) {
                      (*lineptr)[count] = '\0';
                      }
                      }
                      return rc;
                      }

                      int list_fputs(cons t list_type *node, FILE *stream)
                      {
                      int rc = 0;

                      while (node != NULL
                      && (rc = fputs(node -data, stream)) != EOF
                      && (rc = putc('\n', stream)) != EOF)
                      {
                      node = node -next;
                      }
                      return rc;
                      }

                      list_type *list_append
                      (list_type **head, list_type *tail, void *data, size_t size)
                      {
                      list_type *node;

                      node = malloc(sizeof *node);
                      if (node != NULL) {
                      node -next = NULL;
                      node -data = malloc(size);
                      if (node -data != NULL) {
                      memcpy(node -data, data, size);
                      if (*head != NULL) {
                      tail -next = node;
                      } else {
                      *head = node;
                      }
                      } else {
                      free(node);
                      node = NULL;
                      }
                      }
                      return node;
                      }

                      void list_free(list_ type *node, void (*free_data)(vo id *))
                      {
                      list_type *next_node;

                      while (node != NULL) {
                      next_node = node -next;
                      free_data(node -data);
                      free(node);
                      node = next_node;
                      }
                      }

                      /* END new.c */

                      --
                      pete

                      Comment

                      • Marc Bissonnette

                        #12
                        Re: extract all hotmail email addresses in a file and store in separate file

                        pete <pfiland@mindsp ring.comfell face-first on the keyboard. This was
                        the result: news:oeadnWrGl4 RyQMTVnZ2dnUVZ_ s7inZ2d@earthli nk.com:
                        Dennis wrote:
                        >Hi, I have a text file that contents a list of email addresses like
                        >this:
                        >>
                        >"foo@yahoo.com "
                        >"tom@hotmail.c om"
                        >"jerry@gmail.c om"
                        >"tommy@apple.c om"
                        >>
                        >I like to
                        >>
                        >1. Strip out the " characters and just leave the email addresses on
                        >each line.
                        >2. extract out the hotmail addresses and store it into another file.
                        >The hotmail addresses in the original file would be deleted.
                        >>
                        >Thanks for any help
                        >
                        /* BEGIN new.c output */
                        >
                        Original original file contents:
                        "foo@yahoo. com"
                        "tom@hotmail.co m"
                        "jerry@gmail.co m"
                        "tommy@apple.co m"
                        >
                        Final original file contents:
                        foo@yahoo.com
                        jerry@gmail.com
                        tommy@apple.com
                        >
                        Final other file contents:
                        tom@hotmail.com
                        >
                        /* END new.c output */
                        >
                        /* BEGIN new.c */
                        >
                        #include <stdio.h>
                        #include <stdlib.h>
                        #include <string.h>
                        #include <limits.h>
                        >
                        #define STRINGS \
                        { "\"foo@yahoo.co m\"", "\"tom@hotmail. com\"", \
                        "\"jerry@gmail. com\"", "\"tommy@apple. com\""}
                        >
                        struct list_node {
                        struct list_node *next;
                        void *data;
                        };
                        >
                        typedef struct list_node list_type;
                        >
                        void squeeze(char *s1, const int s2);
                        int get_line(char **lineptr, size_t *n, FILE *stream);
                        int list_fputs(cons t list_type *node, FILE *stream);
                        list_type *list_append
                        (list_type **head, list_type *tail, void *data, size_t size);
                        void list_free(list_ type *node, void (*free_data)(vo id *));
                        >
                        int main (void)
                        {
                        int rc;
                        size_t n;
                        char fn[2][L_tmpnam];
                        FILE *fp[2];
                        char *string[] = STRINGS;
                        size_t size = 0;
                        char *buff = NULL;
                        list_type *head = NULL;
                        list_type *tail = NULL;
                        >
                        puts("/* BEGIN new.c output */\n");
                        /*
                        ** Create input file
                        */
                        tmpnam(fn[0]);
                        tmpnam(fn[1]);
                        fp[0] = fopen(fn[0], "w");
                        if (fp[0] == NULL) {
                        fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
                        exit(EXIT_FAILU RE);
                        }
                        for (n = 0; n != sizeof string / sizeof *string; ++n) {
                        fprintf(fp[0], "%s\n", string[n]);
                        }
                        fclose(fp[0]);
                        /*
                        ** Read input file into list
                        */
                        fp[0] = fopen(fn[0], "r");
                        if (fp[0] == NULL) {
                        fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
                        exit(EXIT_FAILU RE);
                        }
                        while ((rc = get_line(&buff, &size, fp[0])) 0) {
                        tail = list_append(&he ad, tail, buff, rc);
                        if (tail == NULL) {
                        fputs("tail == NULL\n", stderr);
                        break;
                        }
                        }
                        fclose(fp[0]);
                        /*
                        ** Display input file contents
                        */
                        puts("Original original file contents:");
                        list_fputs(head , stdout);
                        putchar('\n');
                        /*
                        ** Strip out quotes from strings in memory
                        */
                        for (tail = head; tail != NULL; tail = tail -next) {
                        squeeze(tail -data, '"');
                        }
                        /*
                        ** Create output files
                        */
                        fp[0] = fopen(fn[0], "w");
                        if (fp[0] == NULL) {
                        fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
                        exit(EXIT_FAILU RE);
                        }
                        fp[1] = fopen(fn[1], "w");
                        if (fp[1] == NULL) {
                        remove(fn[0]);
                        fputs("fopen(fn[1]), \"w\") == NULL\n", stderr);
                        exit(EXIT_FAILU RE);
                        }
                        for (tail = head; tail != NULL; tail = tail -next) {
                        if (strstr(tail -data, "hotmail") == NULL) {
                        fprintf(fp[0], "%s\n", tail -data);
                        } else {
                        fprintf(fp[1], "%s\n", tail -data);
                        }
                        }
                        list_free(head, free);
                        tail = head = NULL;
                        fclose(fp[0]);
                        fclose(fp[1]);
                        /*
                        ** Read original file
                        ** Display original file contents
                        */
                        fp[0] = fopen(fn[0], "r");
                        if (fp[0] == NULL) {
                        fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
                        exit(EXIT_FAILU RE);
                        }
                        puts("Final original file contents:");
                        while ((rc = get_line(&buff, &size, fp[0])) 0) {
                        puts(buff);
                        }
                        putchar('\n');
                        fclose(fp[0]);
                        /*
                        ** Read other file
                        ** Display other file contents
                        */
                        fp[1] = fopen(fn[1], "r");
                        if (fp[1] == NULL) {
                        fputs("fopen(fn[1], \"r\") == NULL\n", stderr);
                        exit(EXIT_FAILU RE);
                        }
                        puts("Final other file contents:");
                        while ((rc = get_line(&buff, &size, fp[1])) 0) {
                        puts(buff);
                        }
                        putchar('\n');
                        free(buff);
                        buff = NULL;
                        size = 0;
                        fclose(fp[1]);
                        remove(fn[0]);
                        remove(fn[1]);
                        puts("/* END new.c output */");
                        return 0;
                        }
                        >
                        void squeeze(char *s1, const int c)
                        {
                        char *p;
                        >
                        for (p = s1; *s1 != '\0'; ++s1) {
                        if (c != *s1) {
                        *p++ = *s1;
                        }
                        }
                        *p = '\0';
                        }
                        >
                        int get_line(char **lineptr, size_t *n, FILE *stream)
                        {
                        int rc;
                        void *p;
                        size_t count;
                        /*
                        ** The (char) casts in this function are not required
                        ** by the rules of the C programming language.
                        */
                        count = 0;
                        while ((rc = getc(stream)) != EOF
                        || !feof(stream) && !ferror(stream) )
                        {
                        ++count;
                        if (count == (size_t)-2) {
                        if (rc != '\n') {
                        (*lineptr)[count] = '\0';
                        (*lineptr)[count - 1] = (char)rc;
                        } else {
                        (*lineptr)[count - 1] = '\0';
                        }
                        break;
                        }
                        if (count + 2 *n) {
                        p = realloc(*linept r, count + 2);
                        if (p == NULL) {
                        if (*n count) {
                        if (rc != '\n') {
                        (*lineptr)[count] = '\0';
                        (*lineptr)[count - 1] = (char)rc;
                        } else {
                        (*lineptr)[count - 1] = '\0';
                        }
                        } else {
                        if (*n != 0) {
                        **lineptr = '\0';
                        }
                        ungetc(rc, stream);
                        }
                        count = 0;
                        break;
                        }
                        *lineptr = p;
                        *n = count + 2;
                        }
                        if (rc != '\n') {
                        (*lineptr)[count - 1] = (char)rc;
                        } else {
                        (*lineptr)[count - 1] = '\0';
                        break;
                        }
                        }
                        if (rc != EOF || !feof(stream) && !ferror(stream) ) {
                        rc = INT_MAX count ? count : INT_MAX;
                        } else {
                        if (*n count) {
                        (*lineptr)[count] = '\0';
                        }
                        }
                        return rc;
                        }
                        >
                        int list_fputs(cons t list_type *node, FILE *stream)
                        {
                        int rc = 0;
                        >
                        while (node != NULL
                        && (rc = fputs(node -data, stream)) != EOF
                        && (rc = putc('\n', stream)) != EOF)
                        {
                        node = node -next;
                        }
                        return rc;
                        }
                        >
                        list_type *list_append
                        (list_type **head, list_type *tail, void *data, size_t size)
                        {
                        list_type *node;
                        >
                        node = malloc(sizeof *node);
                        if (node != NULL) {
                        node -next = NULL;
                        node -data = malloc(size);
                        if (node -data != NULL) {
                        memcpy(node -data, data, size);
                        if (*head != NULL) {
                        tail -next = node;
                        } else {
                        *head = node;
                        }
                        } else {
                        free(node);
                        node = NULL;
                        }
                        }
                        return node;
                        }
                        >
                        void list_free(list_ type *node, void (*free_data)(vo id *))
                        {
                        list_type *next_node;
                        >
                        while (node != NULL) {
                        next_node = node -next;
                        free_data(node -data);
                        free(node);
                        node = next_node;
                        }
                        }
                        >
                        /* END new.c */
                        >
                        Wow - All that just to separate @hotmail.com from anything else ? I'm
                        glad I stuck with perl :)

                        --
                        Marc Bissonnette
                        Looking for a new ISP? http://www.canadianisp.com
                        Largest ISP comparison site across Canada.

                        Comment

                        • vippstar@gmail.com

                          #13
                          Re: extract all hotmail email addresses in a file and store inseparate file

                          On Jun 19, 1:02 am, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
                          On Jun 18, 8:33 pm, Dennis <dcho...@gmail. comwrote:
                          >
                          1. Strip out the " characters and just leave the email addresses on
                          each line.
                          >
                          char const *const original = "\"b...@hotmail .com\"";
                          >
                          char buf[50];
                          >
                          strcpy(buf,orig inal);
                          >
                          buf[strlen(original ) - 1] = 0;
                          That does not strip both of the " characters.
                          char const is confusing, and the second const is unnecessary.
                          fix:
                          const char *original = "\"...\"";
                          2. extract out the hotmail addresses and store it into another file.
                          >
                          Take the last 12 characters, make them all lowercase, and then compare
                          with "@hotmail.c om".
                          @ does not belong to C's basic character set, so, that's not possible.

                          Comment

                          • Martijn Lievaart

                            #14
                            Re: extract all hotmail email addresses in a file and store inseparatefile

                            On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:
                            Hi, I have a text file that contents a list of email addresses like
                            this:
                            >
                            "foo@yahoo. com"
                            "tom@hotmail.co m"
                            "jerry@gmail.co m"
                            "tommy@apple.co m"
                            >
                            I like to
                            >
                            1. Strip out the " characters and just leave the email addresses on each
                            line.
                            2. extract out the hotmail addresses and store it into another file. The
                            hotmail addresses in the original file would be deleted.
                            perl -nie 'if (/\@hotmail.com@$/) { s/"//g; print; }' text_file

                            HTH,
                            M4

                            Comment

                            • Bartc

                              #15
                              Re: extract all hotmail email addresses in a file and store in separate file


                              "Marc Bissonnette" <dragnet\_@_/internalysis.co mwrote in message
                              news:Xns9AC29F4 65890dragnetint ernalysisc@216. 196.97.131...
                              pete <pfiland@mindsp ring.comfell face-first on the keyboard. This was
                              the result: news:oeadnWrGl4 RyQMTVnZ2dnUVZ_ s7inZ2d@earthli nk.com:
                              >
                              >Dennis wrote:
                              >>Hi, I have a text file that contents a list of email addresses like
                              >>this:
                              >/* BEGIN new.c output */
                              >><snip 250+ lines of C >
                              Wow - All that just to separate @hotmail.com from anything else ? I'm
                              glad I stuck with perl :)
                              I think pete just enjoys writing huge amounts of C code. Or showing off..

                              I thought my 50-line answer (posted to comp.lang.c only) might have been a
                              bit long because it didn't make clever use of scanf(), but at least it could
                              deal with /any number/ of email addresses from a file.

                              This code I /think/ only deals with the 4 email addresses in the OP's
                              example..

                              --
                              Bartc


                              Comment

                              Working...