problem in awk

Hi frnds,

i have file with 3 columns separated by "|".
and i want to check the $3, if it is 1 then i need to print the $1 and $2.
else
i want to check whether the current $1 is present in any of $2 then i need to print $1 and $1 again. i used the following code, but am getting error can you help me plsss..

s=`awk 'BEGIN{FS="|"}
{
if ($3 ~ /1/)
{print $1" "$2;}
else
{awk -v PNO=$1'{if($2 ~ /PNO/) {print $1" "$1;}}' tst.txt;}
}' tmp1.txt`
echo "$s" > tmp2.txt

You are calling awk from with awk. That is a no-no.

Let's try this:

#    s=`awk 'BEGIN{FS="|"}
# * Instead, just do:
awk -F\| \
#     { 
#     if ($3 ~ /1/)
#       {print $1" "$2;}
#     else
# * Instead, How about...
($3 == "1") 
         {print $1" "$2; next;}
#          
#     {awk -v PNO=$1'{if($2 ~ /PNO/) {print $1" "$1;}}' tst.txt;}
# * Yikes!! How about...
($2 ~ $1) 
         {print $1" "$1; next;}
# Print out the non-matching lines (?)
1
         {print $0;} 
#    }' tmp1.txt`
#    echo "$s" > tmp2.txt
# * Replace with...
} tmp1.txt >tmp2.txt

:confused:Cant we use awk inside awk?
i dont get this clearly frnd.. could you please clear me?

Hi,
If i did not misunderstand your requirement, below one should be ok for you.

input:

a A 1
b B 0
c C 2
d c 1
e E 3
p e 2

output:

a A
c c
d c
e e

code:

cut -d" " -f2 filename > temp
while read line
do
	t=`echo $line | awk '{print $3}'`
	t1=`echo $line | awk '{print $1" "$2}'`
	if [ $t = "1" ]
	then
		echo $t1
	else
		t2=`echo $line | awk '{print $1}'`
		grep $t2 temp 1>/dev/null 2>/dev/null
		if [ $? -le 0 ]
		then
			echo ${t2}" "${t2}
		fi
	fi
	
done < filename

yes, its slightly changed but i got the results from this. thank yo ufrnd.:b: