$ cat in.txt
Linux Unix Linux Windows SUN
MACOS SUN SUN HP-AUX
$ perl -sane 'foreach $i (@F) { $X{$i}+=1 } ; foreach $i (@F) {printf "%s ",$i if $X{$i}==1 };print "\n";%X=""' in.txt
Unix Windows SUN
MACOS HP-AUX
Thanks for the script, it works for one-liners but why the script is not work when I try to modify the script as below.
#!/usr/bin/perl -w
use strict;
my $file = "in.txt";
my %X = ();
open (FH, '<', $file) or die $!;
my @F = <FH>;
foreach my $i (@F)
{
$X{$i}+=1;
}
foreach my $i (@F)
{
if ($X{$i}==1)
{
printf "%s ","$i";
}
}
print "\n";
%X= ();
close (FH);
---------- Post updated at 08:09 AM ---------- Previous update was at 06:36 AM ----------
Hi,
it works with small modification. Thanks
#!/usr/bin/perl -w
use strict;
my %X = ();
open (FH, '<', "in.txt") or die $!;
my @F = <FH>;
my @temp;
foreach my $line (@F)
{
chomp $line;
@temp = split " ", $line;
for my $i ( 0 .. $#temp)
{
$X{$temp[0]}{$temp[$i]}++;
}
}
foreach my $key(keys %X)
{
foreach my $subkey(keys %{$X{$key}})
{
print "$subkey " if $X{$key}{$subkey} == 1;
}
print "\n";
}
close (FH);