awk to add tab to output of both conditions

In the below awk written by @RavinderSingh13 I have added a few lines and am trying to have the output be tab-delimited . The input is space-delimeted and the portion in bold seems to add a tab to the Not found but not the found . Thank you :).

file1

One 1
Two 2
Three 3

file2

One 1
Two 5
Three 3

awk

awk 'FNR==NR{
 A[$2]=$2;
 next
 }
 {
 for(i in A){
 if($2>=i+0 && $2<=A+0){
 $0=$0 " found";
 print;
 next
 }
 };
 printf("%s\t%s\n",$0,($1 ~ /Match/ || $1 ~ /Missing/)?"":" Not found")
 }
 ' file1 file2 > output

Current output

One 1 found
Two 5     Not found     --- tab-delimited 
Three 3 found

Current output --- all tab-delimited

One 1     found
Two 5     Not found
Three 3     found

Hello cmccabe,

Could you please change $0=$0 " found"; to $0=$0 "\tfound"; and let me know if this helps you.

Thanks,
R. Singh

1 Like

Thank you, works great :).