We help IT Professionals succeed at work.

Copy and filter data from one csv file to another with Perl

fabioma
fabioma asked
on
537 Views
Last Modified: 2012-06-27
Dear Experts, I have a csv file that changes time to time, adding new lines and sometimes is erased. Every time this file is changed I need to save the new information, not duplicating the data in another file.
To see if the line already exist in file 2, can be used the value of COL3, because it's always different.
eg.
time 1; copy file1 data to file2
file 1:
col1   col2   col3
AA     BB      A10
AA     FF       A20

file 2:
col1   col2   col3
AA     BB      A10
AA     FF       A20

Time 2: add last lines to file2
file 1:
col1   col2   col3
AA     BB      A10
AA     FF       A20
AA     CC      A30
DD      FF       A40
DD      FA      A35
file 2:
col1   col2   col3
AA     BB      A10
AA     FF       A20
AA     CC      A30
DD      FF       A40
DD      FA      A35

Time 3: the file 1 was erased and has a new line
file 1:
col1   col2   col3
AA     EE      A50
file 2:
col1   col2   col3
AA     BB      A10
AA     FF       A20
AA     CC      A30
DD      FF       A40
DD      FA      A35
AA     EE      A50

Thanks a lot
Fabio
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you ozo, what wonderful script!!! My code was 10 times bigger!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.