If both condition satisfied

pattern
tin loop 3 
tin xarg 1
tin jim  5
tin icon 2 
tin tour 4

patn.out
tin loop 3
tin jim  5
tin icon 1 
tin tour 2

while read one two three
do
awk '$2 ~ /'"$two"'/' patn.out || while read four five six
do
awk -v n1=$three -v n2=$six '{BEGIN (n2<n1)?1:0}'
done<patn.out
done<pattern

my first check is to search a pattern in column 2 of file patn.out and if first is true then check
whether variable $three is less than $six, if it is less than i want to write those lines to a flat file

Output needed for above input:
tin xarg 1            		 ---> xarg i failed in first awk so written in output file
tin icon 2 
tin tour 4

From the above code, I can able to test whether it is less than or not but as we know it is displaying the output
which satisfied in first awk

Do we have single awk line to solve this? if so can you plz explain the command

Hi, you could try:

awk 'NR==FNR{A[$2]=$3; next} !($2 in A) || $3>A[$2]' patn.out pattern

Thanks it works, can you explain how it works?

Hi, it is the same thing as what you were trying to accomplish using shell and awk to do, but entirely in awk, using associative array elements...

awk '
  NR==FNR{                       # When the first file is being read (only then are FNR and NR equal)
    A[$2]=$3                     # create an (associative) element in array A with the second field as the index and the 3rd field as value
    next                         # start reading the next record (line)
  } 
  !($2 in A) || $3>A[$2]         # while reading the second file, if field 2 is not present in array A, OR if it is present, but $3 is more than A[$2] (the previously recorded $3 from path.out for that particular $2) then print the record (line) 
' patn.out pattern               # first read patn.out as the first file and then 'pattern' as the second file