How to update a txt file with another txtfile?

R

ricky

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
 
K

krakle

Purl Gurl said:
ricky wrote:

(snipped)



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?
 
I

Ian Wilson

ricky said:
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
 
G

Gunnar Hjalmarsson

krakle said:
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.
 
K

krakle

Gunnar Hjalmarsson said:
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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top