Processing a portion of a file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anilga
    New Member
    • Jul 2007
    • 3

    Processing a portion of a file.

    Hi ,

    I want to grep for multiple lines, like

    ;START
    ;copy here
    ;END

    I need to grep from ;START to ;END
    I am using windiws XP.

    Please let me know if anybody can help.

    I tried
    grep /^;START[.*][\n];END$/mi, <FILE>;


    Thanks
    Anil
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Take a look at the Range Operator on perldoc, and do your file processing using a while loop.

    - Miller

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      you need to return the value of grep to an array:
      Code:
      my @lines = grep /^;START[.*][\n];END$/mi, <FILE>;
      [.*] is a character class of a dot and an asterisk, not the same as (.*) which captures the pattern in memory, and [\n] is not needed if this really is a multiline match.

      try like this:

      Code:
      my @lines = grep /^;START(.*);END$/mi, <FILE>;

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        [CODE=perl]
        my @lines = grep {/^;START/../^;END/} <DATA>;

        print @lines;

        __DATA__
        more stuff
        and yet
        ;START
        ;copy here
        ;END
        final stuff
        and yet
        [/CODE]

        - Miller

        Comment

        Working...