Perl Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SANDY1722
    New Member
    • Sep 2007
    • 6

    Perl Help

    I have a unix file:

    file contents:

    foo.text:

    s_map_test
    $$param_name_20 070919112345

    I want to extract only the 2nd part of the line, and write to new file - foo.out

    The New file should have:

    foo.out:
    20070919112345

    Thanks for help
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by SANDY1722
    I have a unix file:

    file contents:

    foo.text:

    s_map_test
    $$param_name_20 070919112345

    I want to extract only the 2nd part of the line, and write to new file - foo.out

    The New file should have:

    foo.out:
    20070919112345

    Thanks for help
    Will all of the data in your source file have the same format for the data? ($$param_name_2 0070919112345) In other words, will there be the two underscores everytime or will it vary? Can you provide a sample of several lines so we can possibly see the pattern?

    Thanks!

    Regards,

    Jeff

    Comment

    • SANDY1722
      New Member
      • Sep 2007
      • 6

      #3
      Originally posted by numberwhun
      Will all of the data in your source file have the same format for the data? ($$param_name_2 0070919112345) In other words, will there be the two underscores everytime or will it vary? Can you provide a sample of several lines so we can possibly see the pattern?

      Thanks!

      Regards,

      Jeff
      ------------------------------------------

      Jeff,

      the file is going to be generated on Ad-hoc basis daily.

      todays file:

      s_map_test
      $$paramname_200 70919112345

      out file: 20070919112345

      Tommorows file:

      s_map_test
      $$paramname_200 70920112346

      out file:

      20070920112346

      Note: there is only one underscore (_), instead of two.

      I just need the numeric portion from 2nd line in the source file, and write it to a new file.

      Thanks a lot
      Sandy

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Originally posted by SANDY1722
        ------------------------------------------

        Jeff,

        the file is going to be generated on Ad-hoc basis daily.

        todays file:

        s_map_test
        $$paramname_200 70919112345

        out file: 20070919112345

        Tommorows file:

        s_map_test
        $$paramname_200 70920112346

        out file:

        20070920112346

        Note: there is only one underscore (_), instead of two.

        I just need the numeric portion from 2nd line in the source file, and write it to a new file.

        Thanks a lot
        Sandy
        Normally we would want to see your code before providing you any, but I am in a code generating mood at the moment. See if the following does what you want:

        The data I used was:

        paramname_20070 920112346

        I took off the $$ at the beginning, assuming that they would not be there. If they are, you can modify the regex to include them.

        Here is the code I used:

        [code=perl]
        use strict;
        use warnings;

        open(DATA, "<data.txt" );

        while(<DATA>)
        {
        if($_ = m/\D+\_(\d+)$/)
        {
        print("The number is: $1\n");
        }
        else
        {
        print("Regex didn't find anything!\n");
        }
        }
        [/code]

        Regards,

        Jeff

        Comment

        • SANDY1722
          New Member
          • Sep 2007
          • 6

          #5
          Originally posted by numberwhun
          Normally we would want to see your code before providing you any, but I am in a code generating mood at the moment. See if the following does what you want:

          The data I used was:

          paramname_20070 920112346

          I took off the $$ at the beginning, assuming that they would not be there. If they are, you can modify the regex to include them.

          Here is the code I used:

          [code=perl]
          use strict;
          use warnings;

          open(DATA, "<data.txt" );

          while(<DATA>)
          {
          if($_ = m/\D+\_(\d+)$/)
          {
          print("The number is: $1\n");
          }
          else
          {
          print("Regex didn't find anything!\n");
          }
          }
          [/code]

          Regards,

          Jeff
          -----------------------------

          Thanks jeff

          Comment

          Working...