Grep

pll at lanminds.com pll at lanminds.com
Thu Jan 30 12:04:31 EST 2003


In a message dated: 30 Jan 2003 11:24:00 EST
"Kenneth E. Lussier" said:

>I apologize. I mis-spoke my intent. I don't actually want to remove
>*ALL* of the blank lines, since that would create a single, really long
>entry. There has to be one blank line between each entry.
[...snip...]
>currently, it looks like this:
>
>dn: uid=joe at zuken.com, ou=country, ou=contacts, ou=people,
>dc=zuken,dc=com
>objectclass: top
>objectclass: person
>objectclass: organizationalPerson
>objectclass: inetOrgPerson
>
>givenName: Joe
>sn: Shmoe
>cn: Joe Shmoe
>mail: joe at zuken.com
>
>telephoneNumber: 555-555-1212

I think this might do it:

	#!/usr/bin/perl

	@F = <>;

	for ($i = 0; $i < $#F; $i++) {
	  if ( ( $F[$i] !~ /^\s*$/ ) || ($F[$i + 1] =~ /^dn/) ) {
	    print "$F[$i]";
	  }
	}

I tried really hard to turn this into a one-liner, but but I couldn't 
do it using the -ane.  Part of the problem was that I was relying 
upon [$. + 1] to index into @F to look at the next line.  But since 
we're dealing with stdin, there is no next line (or previous line) 
there's only the current line.

Of course, Kevin solves that by taking the easy approach and using a 
regex to operate on the current line :)  His solution is by far the 
more elegant and better approach!
-- 

Seeya,
Paul
--
Key fingerprint = 1660 FECC 5D21 D286 F853  E808 BB07 9239 53F1 28EE

	It may look like I'm just sitting here doing nothing,
   but I'm really actively waiting for all my problems to go away.

	 If you're not having fun, you're not doing it right!





More information about the gnhlug-discuss mailing list