Hi everyone,

here is a pastebin link to my question in case I formatted this incorrectly: https://pastebin.com/E1sy9s2B

I have a list of text correspondence that references a “handle_id” number for contact info. The “handle_id” is associated with a phone number or email address which is stored in a list in a separate file. I am trying to replace the “handle_id =” string found in messages.txt with the “id =” string found in contacts.txt The lists look like this:

contacts.txt :

handle_id = 868 id = aust@email.com

handle_id = 920 id = tara@email.ca

handle_id = 921 id = gram@email.ca

handle_id = 922 id = +17786771234

handle_id = 923 id = +12508891234

handle_id = 924 id = +12502171234

handle_id = 925 id = +12508891234

handle_id = 926 id = +12505801234

handle_id = 927 id = +17789701234

handle_id = 970 id = +16137941234

messages.txt :

handle_id = 1541 Sent Fri Mar 23 13:41:02 2018

text = Hi Partner: Called your house & learned you are out at a mtg.

handle_id = 1541 Received Fri Mar 23 16:12:25 2018

text = I got you bud

handle_id = 970 Sent Fri Mar 23 16:13:56 2018

text = Please pickup milk.

What I’m trying to do is search for the “handle_id = XXX” string in messages.txt and replace it with the associated “id =” string found in contacts.txt. To put it another way, I want to search messages.txt for any matches from “column A” in contacts.txt, if a match is found, overwrite it with the “id =” string next to the match in “column B” so that it looks something like this:

MESSAGE LIST:

id = +12507741234 Sent Fri Mar 23 13:41:02 2018

text = Hi Partner: Called your house & learned you are out at a mtg.

id = +12507741234 Received Fri Mar 23 16:12:25 2018

text = I got you bud

id = +16137941234 Sent Fri Mar 23 16:13:56 2018

text = Please pickup milk.

Any help would be much appreciated, thanks!


In reply to Search and replace from one list to another by NicheArchitecture

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.