Description

This perl script will provide grep-like functionality to return multi-line (record) matches for

blank-line deliminated files such as LDIF files used by LDAP. A match on any line will return

all lines from the previous blank line until the following one.

here this is the script

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

#!/usr/bin/perl -w use strict; my $search = shift; my $file = shift; my $out = shift; if (! $file) { open(INF, '-') or die("Unable to open STDIN\n"); } else { open(INF, $file) or die("Unable to open $file\n"); } my @buffer; while (<INF>) { my $line = $_; if ($line eq "\n") { my $count = 0; #@buffer = ""; undef @buffer; } else { $buffer[$#buffer+1] = $line; } if (/$search/io) { my $buf; foreach $buf (@buffer) { print $buf; } while (($out = <INF>) ne "\n") { print $out; } undef @buffer; print "\n"; } }

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

when execute the script, it gives me this error message below, please help me to correct the script to avoid the error below as well as display as per format i want below

Use of uninitialized value in print at ./ldifgrep line 30, <INF> line 24.

Use of uninitialized value in string ne at ./ldifgrep line 30, <INF> line 24.

Use of uninitialized value in print at ./ldifgrep line 30, <INF> line 24.

Use of uninitialized value in string ne at ./ldifgrep line 30, <INF> line 24.

Use of uninitialized value in print at ./ldifgrep line 30, <INF> line 24.

Use of uninitialized value in string ne at ./ldifgrep line 30, <INF> line 24.

the line 59 is at this line ---> while (($out = <INF>) ne "\n")

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

check out the sample LDIF File below I need to grep the full dn: and the next line attribute mail only

dn: uid=testing,ou=comp,o=test.com dpwnc: BH mail: example@great.com sn: example dn: uid=testing1,ou=comp,o=test.com dpwnc: CH mail: example1@great.com sn: example1 dn: uid=testing2,ou=comp,o=test.com dpwnc: DH mail: example2@great.com sn: example2

i want the output generated into new file with the format below

dn: uid=testing,ou=comp,o=test.com mail: example@great.com dn: uid=testing1,ou=comp,o=test.com mail: example1@great.com dn: uid=testing2,ou=comp,o=test.com mail: example2@great.com

In reply to Help please, or Urgent help needed! by anakin30

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.