anakin30 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help please, or Urgent help needed!
by SuicideJunkie (Vicar) on Mar 27, 2012 at 18:55 UTC | |
by anakin30 (Acolyte) on Mar 27, 2012 at 19:55 UTC | |
by remiah (Hermit) on Mar 27, 2012 at 20:45 UTC | |
by anakin30 (Acolyte) on Mar 28, 2012 at 02:51 UTC | |
by remiah (Hermit) on Mar 28, 2012 at 03:10 UTC | |
| |
Re: Help please, or Urgent help needed!
by MidLifeXis (Monsignor) on Mar 28, 2012 at 13:18 UTC |