Need to match a value and print the subsequent lines to output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perlnoob
    New Member
    • May 2007
    • 1

    Need to match a value and print the subsequent lines to output

    Hello,

    I am noob to Perl Programming. Here's what I need to do. I need to match a string value from a file and upon matching the value, I need the remainder of the file to be printed to an output.

    For example: Here's the File I'll be reading:

    Hilton also told Superior Court Judge Michael T. Sauer she was trying to take more responsibility for her life. This, after Hilton essentially laid the blame for her troubles on longtime publicist Elliot Mintz, whom she said told her the license was only suspended for 30 days, through last December, while it had actually been suspended into March.


    Value to match = Elliot

    Reqd Output:

    Elliot Mintz, whom she said told her the license was only suspended for 30 days, through last December, while it had actually been suspended into March.


    Here's the code i have so far:

    open (FILE, "$infile") or die "Cannot Open Log File!\n";
    open (DAT,">$outfile ") || die("Cannot Open File");

    while (@variable = <FILE>) {
    for (@variable =~ /Building Configuration/) {
    # write to the data file
    print DAT "@variable\ n";
    }
    }
    close DAT;
    close FILE;
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Is this school/class work?

    Comment

    • jjeanj1
      New Member
      • May 2007
      • 18

      #3
      hi this is what i have i saw your post and i remember i had a samll routine that does that. You can try that. Tell me if you need more info.

      $INPUT = "input.txt" ;
      $outfile ="out.txt";

      open(INPUT) or die("Could not open input file.");
      open (DAT,">$outfile ") || die("Cannot Open File");

      foreach $line (<INPUT>) {
      chomp($line);
      if($line=~ /(\Elliot)/){ # do line-by-line processing.
      print DAT "$line\n";
      }


      }
      close(INPUT);

      Comment

      Working...