i want to search for each line that has 'available' in it, look at the first value (for example, ajay, singh) and delete any records that has these values (the output will have only the lines with 'kumar' left.
what i meant is, delete any lines that match 'ajay' and 'singh' that are the first field of the lines with 'available' and keep the remaining lines (in the example, lines with kumar in them.)
In your example, I will get no output as there is no "kumar" in any lines with "available".
What I need is, I have to look at every line that has "available" in it, extract the first word (ajay, singh), delete any records that matches those words, and print the remaining daya (that will have records with "kumar" in them, in this example.)
#!/usr/bin/perl
open FH,"<a.txt";
while(<FH>){
my @tmp=split(" ",$_);
$hash{$tmp[0]}++ if $tmp[$#tmp] eq "available";
push @arr,$_;
}
close FH;
foreach(@arr){
my @tmp=split(" ",$_);
print if not exists $hash{$tmp[0]};
}