Hi Gurus,

I'm looking to iterate a file and if find specific word then store the other lines following that which matches specific pattern.The ldap.txt file is pretty large in several Gigs.

user.txt
test1

game

ldap.txt
dn: uid=test1,ou=people,dc=admin,dc=local

blah

blah

maillocaladdress: test1@example.com

maillocaladdress: test.team@example.com

maillocaladdress: test11@example.com

some date

some more data

data


dn: uid=game,ou=people,dc=admin,dc=local

blah

blah

maillocaladdress: game@example.com

maillocaladdress: game.test@example.com

maillocaladdress: game-test@example.com

some date

some more data

data

and so on..


Open user.txt and iterate through each user and check each line on ldap.txt in dn: line. If matches, then store the value of all the lines matching maillocaladdress to the varialbe , I assume in hash key/value pari but here the values are more than one.


e.g.

test1 matches dn: uid=test1,ou=people,dc=admin,dc=local

Store the following values for each user.

test1@example.com

test.team@example.com

test11@example.com

Thank you for all your help & support.


In reply to File Iteration and looking for specific matching data by bshah

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.