How to update a txt file with another txtfile?

Discussion in 'Perl Misc' started by ricky, Jun 19, 2004.

  1. ricky

    ricky Guest

    I have the following tab delimited master.txt file which has about
    1000 records and looks like this:

    NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom"
    NTADPH0892M00 Standard; Prime Shift Monitoring WST None "JOHNSON, DON"
    ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
    ntadph0961m00 Standard; Prime Shift Monitoring WST None "Wayne, John"
    NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam"

    Then I have a tab delimited update.txt file which has about 1000
    records also and looks like this:

    NTAPTH0236M01 19687 307 1 1
    NTADPH0853M00 31612 508 9 24
    NTAPTH0271M00 21735 307 4 4
    ntadph0919m00 19072 301 2 3
    NTADPH0964L01 18000 307 4 4

    I want to create a Perl script that will check for matches with the
    update.txt file against the first field in the master.txt file. If a
    match is found the master.txt file would be appended with the last
    four fields from the update.txt file.
    There are 3 records from the update.txt file that are found in the
    master.txt file in the above example.

    The result would look like this:

    NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom" 31612 508 9
    24
    ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
    19072 301 2 3
    NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam" 18000
    307 4 4

    I also want to produce an error listing of all the records in the
    update.txt file that don't match up with the master.txt file.

    thanks
     
    ricky, Jun 19, 2004
    #1
    1. Advertising

  2. ricky

    krakle Guest

    Purl Gurl <> wrote in message news:<>...
    > ricky wrote:
    >
    > (snipped)
    >
    > > I want to create a Perl script that will check for matches

    >
    > > I also want to produce an error listing of all the records

    >
    > So, do so.
    >
    > Using your time, here, to advise readers what you
    > want to do, will not accomplish your task, yes?
    >
    >
    > Purl Gurl



    I suppose you don't know how to read and logically put 1 & 2
    together... He was basically asking a non-direct question. He was
    using his time, here, to seek advice on something he didn't know how
    to do (notice how you snipped the beginning of the post disregarding
    the rest?)... What did your response accomplish other than wasting
    space?
     
    krakle, Jun 21, 2004
    #2
    1. Advertising

  3. ricky

    Ian Wilson Guest

    ricky wrote:

    > I have the following tab delimited master.txt file which has about
    > 1000 records and looks like this:
    >
    > NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom"
    > NTADPH0892M00 Standard; Prime Shift Monitoring WST None "JOHNSON, DON"
    > ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
    > ntadph0961m00 Standard; Prime Shift Monitoring WST None "Wayne, John"
    > NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam"
    >
    > Then I have a tab delimited update.txt file which has about 1000
    > records also and looks like this:
    >
    > NTAPTH0236M01 19687 307 1 1
    > NTADPH0853M00 31612 508 9 24
    > NTAPTH0271M00 21735 307 4 4
    > ntadph0919m00 19072 301 2 3
    > NTADPH0964L01 18000 307 4 4
    >
    > I want to create a Perl script that will check for matches with the
    > update.txt file against the first field in the master.txt file. If a
    > match is found the master.txt file would be appended with the last
    > four fields from the update.txt file.
    > There are 3 records from the update.txt file that are found in the
    > master.txt file in the above example.
    >
    > The result would look like this:
    >
    > NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom" 31612 508 9
    > 24
    > ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
    > 19072 301 2 3
    > NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam" 18000
    > 307 4 4


    read the updates into a hash
    whilst reading master
    if the hash exists for that key
    print oldstuff and hashvalue to newfile

    > I also want to produce an error listing of all the records in the
    > update.txt file that don't match up with the master.txt file.


    undefine the hash elements as you emit them
    at the end, print remaining hash elements
     
    Ian Wilson, Jun 21, 2004
    #3
  4. krakle wrote:
    > Purl Gurl wrote:
    >> ricky wrote:
    >>
    >> (snipped)
    >>
    >>> I want to create a Perl script that will check for matches

    >>
    >>> I also want to produce an error listing of all the records

    >>
    >> So, do so.
    >>
    >> Using your time, here, to advise readers what you want to do,
    >> will not accomplish your task, yes?

    >
    > He was basically asking a non-direct question. He was using his
    > time, here, to seek advice on something he didn't know how to do


    To me it seems as if OP just hoped that somebody would do the job
    (homework?) for him, and that he was using his time to compose (copy &
    paste?) and post a job specification. He didn't post any code, and he
    did not indicate in any other way that he had made any own efforts
    whatsoever to accomplish the task by help of the docs or the FAQ or
    anything.

    > What did your response accomplish other than wasting space?


    It might discourage others from posting similar job specifications. In
    that case, it will serve a good purpose.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jun 22, 2004
    #4
  5. ricky

    krakle Guest

    Gunnar Hjalmarsson <> wrote in message news:<>...
    > It might discourage others from posting similar job specifications. In
    > that case, it will serve a good purpose.


    Or discourage people from posting period. After a while noone wants to
    post to a newsgroup where they will receive "snotty" and "sarcastic"
    replies just because someone didn't 'like' their post...
     
    krakle, Jun 23, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Carnahan

    File Access error - writing to .txt file

    John Carnahan, Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    805
    John Carnahan
    Jul 18, 2003
  2. gikuh
    Replies:
    1
    Views:
    386
    Steve Pugh
    Jul 10, 2003
  3. Sameen
    Replies:
    2
    Views:
    447
    Victor Bazarov
    Aug 29, 2005
  4. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,582
    Roedy Green
    Sep 15, 2011
  5. Replies:
    4
    Views:
    105
Loading...

Share This Page