bt707
asked on
perl - compare and print if
I have a file with record entries seperated by new line like....
dn: cn=Alain Buisson 100111,ou=employee,o=xyz,c =xx
uid: alain-19850590
icsCalendar: alain-19850590
dn: cn=Alain Lecourt 100134,ou=employee,o=xyz,c =xx
uid: alain-19820986
icsCalendar: alain-19820000
dn: cn=Alain Mamessier 100345,ou=employee,o=xyz,c =xx
uid: alain-19720975
icsCalendar: alain-19720975
dn: cn=Alain Menez 100398,ou=employee,o=xyz,c =xx
uid: alain-19779408
icsCalendar: alain-19779408
from each record (set of 3 lines) I need to find the ones where the
uid and icsCalendar does NOT match.
So for this exampel I would get a result of
dn: cn=Alain Lecourt 100134,ou=employee,o=xyz,c =xx
uid: alain-19820986
icsCalendar: alain-19820000
Haven't been able to get it to come out right.
Thanks,
dn: cn=Alain Buisson 100111,ou=employee,o=xyz,c
uid: alain-19850590
icsCalendar: alain-19850590
dn: cn=Alain Lecourt 100134,ou=employee,o=xyz,c
uid: alain-19820986
icsCalendar: alain-19820000
dn: cn=Alain Mamessier 100345,ou=employee,o=xyz,c
uid: alain-19720975
icsCalendar: alain-19720975
dn: cn=Alain Menez 100398,ou=employee,o=xyz,c
uid: alain-19779408
icsCalendar: alain-19779408
from each record (set of 3 lines) I need to find the ones where the
uid and icsCalendar does NOT match.
So for this exampel I would get a result of
dn: cn=Alain Lecourt 100134,ou=employee,o=xyz,c
uid: alain-19820986
icsCalendar: alain-19820000
Haven't been able to get it to come out right.
Thanks,
ASKER
nbkbar7,
that pulls out some of them but also pulls out a lot of them that ARE that same that I don't want.
Not sure why yet, still working on that.
Thanks,
that pulls out some of them but also pulls out a lot of them that ARE that same that I don't want.
Not sure why yet, still working on that.
Thanks,
perl -00ne 'print unless /uid:(.*)\nicsCalendar:\1\ n/' in.dat
Do the lines that you don't wand have different whitespace around uid or icsCalendar?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ozo,
all the lines for icsCalendar and uid are the same on format and whitespaces, after running your one liner I seen the only issue I had was because of some case that was different between the two so added the "i" and works just fine.
That's just what I was trying to do using a one liner and the -00ne but couldn't get the compare to work, your one liner works perfect.
Appreciate it.
Thanks
all the lines for icsCalendar and uid are the same on format and whitespaces, after running your one liner I seen the only issue I had was because of some case that was different between the two so added the "i" and works just fine.
That's just what I was trying to do using a one liner and the -00ne but couldn't get the compare to work, your one liner works perfect.
Appreciate it.
Thanks
#
$file = "in.dat";
my $dn = "";
my $uid = "";
my $tag = "";
my $data = "";
my $uidData = "";
my $icsCalendarData = "";
open (FILE, $file);
while (<FILE>) {
$line = $_;
($tag, $data) = split(":", $line);
if ($tag =~ "dn") {
$dn = $line;
} elsif ($tag =~ "uid") {
$uid = $line;
$uidData = $data;
} elsif ($tag =~ "icsCalendar") {
if (not ($uidData eq $data)) {
printf("%s%s%s\n", $dn, $uid, $line);
}
$dn = "";
$uid = "";
$line = "";
}
}
that help?