http://www.perlmonks.org?node_id=1017966


in reply to Help asked for creating a file with usernames

A more long-winded approach would be to read and print the file line by line and, if we have found an address line, print the two new preceding lines and add the /32 at the end.

$ perl -Mstrict -Mwarnings -e ' > open my $usersFH, q{<}, \ <<EOD or die open qq{open: < HEREDOC: $!\n +}; > dn: uid=donald,nameSpace=mydomain.com,ou=users,o=sp > radiusFramedAddress: 192.168.0.2 > > dn: uid=mario,nameSpace=mydomain.com,ou=users,o=sp > radiusFramedAddress: 192.168.0.7 > > dn: uid=thijs,nameSpace=mydomain.com,ou=users,o=sp > radiusFramedAddress: 192.168.11.15 > EOD > > while ( <$usersFH> ) > { > if ( m{^radiusFramedAddress:} ) > { > print > qq{changeType: modify\nreplace: radiusFramedAddress\n}; > s{$}{/32}; > } > print; > }' dn: uid=donald,nameSpace=mydomain.com,ou=users,o=sp changeType: modify replace: radiusFramedAddress radiusFramedAddress: 192.168.0.2/32 dn: uid=mario,nameSpace=mydomain.com,ou=users,o=sp changeType: modify replace: radiusFramedAddress radiusFramedAddress: 192.168.0.7/32 dn: uid=thijs,nameSpace=mydomain.com,ou=users,o=sp changeType: modify replace: radiusFramedAddress radiusFramedAddress: 192.168.11.15/32 $

I hope this is helpful.

Cheers,

JohnGG