Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] Separating data into different files

Expand Messages
  • Prasanna Goupal
    Hi, Please use following code. ####################################################### #!/usr/bin/perl use strict; my $line; while($line = ) { my @array
    Message 1 of 5 , Aug 2, 2005
      Hi,

      Please use following code.

      #######################################################

      #!/usr/bin/perl

      use strict;
      my $line;

      while($line = <STDIN>)
      {
      my @array = split(" ",$line);
      my @digit = split(/\./,$array[0]);
      open(INFILE,">>file.$digit[1]") || die "Error in opening file";
      print INFILE $line;
      close(INFILE);
      }
      exit 0;

      #######################################################

      Run your program as perl file.pl < Inputfile.txt

      Regards,

      Prasanna

      ~


      apsawant <apsawant@...> wrote:
      Hi All,

      I am a beginner in perl.
      I want to separate the contents of a file (shown below) into different
      files.
      The contents of the file DATA are:
      ------------------------------------
      10.05.2005 10:00 - amit
      10.05.2005 10:10 - amit
      10.05.2005 10:20 - prakash
      10.05.2005 10:40 - amit
      10.05.2005 10:50 - amit
      11.05.2005 10:00 - prakash
      11.05.2005 10:10 - amit
      11.05.2005 10:20 - amit
      11.05.2005 10:40 - amit
      11.05.2005 10:50 - amit
      10.06.2005 10:00 - amit
      10.06.2005 10:10 - prakash
      10.06.2005 10:20 - amit
      10.06.2005 10:40 - amit
      10.06.2005 10:50 - amit
      11.06.2005 10:00 - amit
      11.06.2005 10:10 - amit
      12.06.2005 10:20 - prakash
      13.06.2005 10:40 - amit
      14.06.2005 10:50 - amit
      10.07.2005 10:00 - amit
      10.07.2005 10:10 - prakash
      10.07.2005 10:20 - amit
      10.07.2005 10:40 - amit
      10.07.2005 10:50 - amit
      11.07.2005 10:00 - amit
      11.07.2005 10:10 - prakash
      14.07.2005 10:20 - amit
      17.07.2005 10:40 - amit
      19.07.2005 10:50 - prakash
      ------------------------------------

      The contents of the separate file should be as follows:

      file.05
      --------
      10.05.2005 10:00 - amit
      10.05.2005 10:10 - amit
      10.05.2005 10:20 - prakash
      10.05.2005 10:40 - amit
      10.05.2005 10:50 - amit
      11.05.2005 10:00 - prakash
      11.05.2005 10:10 - amit
      11.05.2005 10:20 - amit
      11.05.2005 10:40 - amit
      11.05.2005 10:50 - amit

      file.06
      --------
      10.06.2005 10:00 - amit
      10.06.2005 10:10 - prakash
      10.06.2005 10:20 - amit
      10.06.2005 10:40 - amit
      10.06.2005 10:50 - amit
      11.06.2005 10:00 - amit
      11.06.2005 10:10 - amit
      12.06.2005 10:20 - prakash
      13.06.2005 10:40 - amit
      14.06.2005 10:50 - amit

      file.06
      --------
      10.07.2005 10:00 - amit
      10.07.2005 10:10 - prakash
      10.07.2005 10:20 - amit
      10.07.2005 10:40 - amit
      10.07.2005 10:50 - amit
      11.07.2005 10:00 - amit
      11.07.2005 10:10 - prakash
      14.07.2005 10:20 - amit
      17.07.2005 10:40 - amit
      19.07.2005 10:50 - prakash


      Basically, I want to separate the contents of the file DATA containing
      all the data into separate files such that it contains the data for
      each month (05, 06, 07) and names the file name as file.month (in this
      particular example, file.05, file.06, file.07).
      Any help is highly appreciated.

      Thanks,
      Amit.




      Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html



      ---------------------------------
      YAHOO! GROUPS LINKS


      Visit your group "perl-beginner" on the web.

      To unsubscribe from this group, send an email to:
      perl-beginner-unsubscribe@yahoogroups.com

      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


      ---------------------------------




      ---------------------------------
      Start your day with Yahoo! - make it your home page

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.