troubleshooting Question

Merging two files with Perl

Avatar of Steve Jennings
Steve Jennings asked on
Shell ScriptingPerl
5 Comments2 Solutions298 ViewsLast Modified:
I have 2 files that I need to compare and merge. File1 has 3 fields: device_name, status, days_in_cur_status. File1 is the "master status" file.

File2 has 2 fields: device_name, status. File2 is the file produced from checking the current status.

- File1 -
deviceA available 10
deviceB available 8
deviceC unavailable 3

- File2 -
deviceA available
deviceB unavailable
deviceC available
deviceD available

After comparing/merging the files I'd like to produce File3 which should look like:

deviceA available 11
deviceB unavailable 0
deviceC available 0
deviceD available 0

I can't figure out how to open both files and compare a line in file1 to each line in file2. I began by reading both files into an array and then iterating through the arrays, but that's not working. I'd be glad to post the code, but I'm pretty sure that having to read thru file 2 once for each line in file 1 is, well, dumb.



Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros