I have two files. One is an HR record of the user's values; the other is a network export of their attributes. I am trying to compare the two files and find the differences attribute by attribute. The sole reliable key is the samaccountname which is present and consistent in every record. I am trying to produce a file like this:

barsu991,title,Director of Cooks zingk072,symphonyemployeetype,IKP zingk072,employeenumber,zingk072 zingk072,manager,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"
Where each line of the produced file holds the samaccountname,attribute that is incorrect, and the correct value of the attribute from the HR record. One mistake per line.

I have tried to do this with loops like below but the best I get is a comparison with the last line and not all of them.

open(HR, "<hr.txt") || die "can't open hr"; open(AD, "<ad.txt") || die "can't open ad"; open(COMMAND, ">com.txt") || die "can't open com.txt"; while(<HR>) { ($samaccountnameHR,$givennameHR,$snHR,$initialsHR, $employeenumberHR,$symphonyemployeetypeHR,$mailHR, $titleHR,$departmentHR,$companyHR,$lHR, $physicaldeliveryofficeHR,$streetaddressHR,$stHR, $postalcodeHR,$telephonenumberHR,$managerHR)=split(/,$/); while(<AD>) { ($samaccountnameAD,$givennameAD,$snAD,$initialsAD,$employeenumberAD, $symphonyemployeetypeAD,$mailAD, $titleAD,$departmentAD,$companyAD, $lAD,$physicaldeliveryofficeAD,$streetaddressAD,$stAD,$postalcodeAD, $telephonenumberAD,$managerAD)=split(/,$/); if ($employeenumberHR != $employeenumberAD) { print "$samaccountnameHR $samaccountnameAD\n"; } } }
HR Data: samaccountname,givenname,sn,initials,employeenumber, symphonyemployeetype,mail,title,department,company,l, physicaldeliveryoffice,streetaddress,st,postalcode, telephonenumber,manager barsu991,Uttiam,Barski,K,20114598,IKP, Uttiam.Barski@pulse.org,Director of Cooks,Day Kitchen, MILIFO,Alpena,Kitchen of the World,400 Baker,WI,50987, 555-555-5555,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" walkl003,Lreblemet,Walker,J,20178941,IKP, Lreblemet.Walker@pulse.org,Head Cook,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987,555-555-5551, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" karss001,Sovyetk,Karsten,Y,20146598,IKP,Sovyetk.Karsten@pulse.org, Dishwasher,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" zingk072,Kovon,Zingerman,K,20113578,IKP,Kovon.Zingerman@pulse.org, Baker,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" peizs194,Synthia,Smite,B,20134743,IKP,Synthia.Peizer@pulse.org, Broiler Man,Day Kitchen,MILIFO,Alpena, Kitchen of the World,205 Willy B. Temple, WI,50987,,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" hutcy231,Yello,Hutchinson,W,20145712,IKP, Yello Hutchinson,@pulse.org, Bottle Washer,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987, ,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" haserz221,Zebediah,Haserkrilk,L,20125471,IKP, Zebediah.Haserkrilk@kit.org, Purchaser,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987, ,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"
AD data: samaccountname,givenname,sn,initials,employeenumber, symphonyemployeetype,mail,title,department,company,l, physicaldeliveryoffice,streetaddress,st,postalcode, telephonenumber,manager barsu991,Uttiam,Barski,K,20114598,IKP, William.Barski@pulse.org,Chief of Cooks,Day Kitchen, MILIFO,Alpena,Kitchen of the World,400 Baker,WI,50987, 555-555-5555, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" walkl003,Larry,Walker,J,,IKP,Larry.Walker@pulse.org, Cook,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 400 Baker,WI,50987,555-555-5551, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" karss001,Steven,Karsten,Y,20146598,IKP, Steven.Karsten@pulse.org,Dishw,Day Kitchen,MILIFO, Alpena,Sully's Kitchen,48720 Belcard,IL,34567,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" zingk072,Kevin,Zingerman,K,,,Kevin.Zingerman@pulse.org, Baker,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, peizs194,Samantha,Smith,B,20134743,IKP, Samantha.Smith@pulse.org,"Man, Broiler",Day Kitchen, MILIFO,Alpena,Kitchen of the World,205 Willy B. Temple, WI,50987,,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" hutcy231,Yaren,Hutchinson,W,20145712,IKP, Yaren Hutchinson,@pulse.org,Bottle Washer,Day Kitchen,MILIFO, Alpena,Kitchen of the World,400 Baker,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" haserz221,Zebediah,Hasermann,L,,IKP, Zebediah.Haserman@pulse.org,Purchaser,Day Kitchen,MILIFO, Alpena,Kitchen of the World,400 Baker,WI,50987,555-555-5555, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"


In reply to Comparing two files line by line and exporting the differences from the first file by jzelkowsz

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.