string manipulation

i have a file that contains a pattern like this:

ajay 1234 newyork available
kumar 2345 denver
singh 2345 newyork
ajay 3456 denver
kumar 3456 newyork
singh 3456 delhi available
ajay 4567 miami
kumar 4567 miami
singh 4567 delhi

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.

how to do this? any suggestions?

let me know if u have further questions.

thanks,

ajay

is this what you want?

cat Somefile | grep available | grep kumar

This will only show lines with available AND kumar in the line.

Ikon,

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.)

Does that clear?

Thanks,

ajay

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.)

Can you provide your expected output from your given 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]};
}