Vlookup using awk non similar files

I need to vlookup and check the server not found.

Source file 1

server1
server2
server3
server4
server5_root
server6_silver
server7
server7-test
server7-temp


Source file 2

server1_bronze
server1_root_bronze
server2_d1_silver
server2_d2_silver
server2_d3_silver
server2_d4_silver
server2_ls_silver
server3_silver
server7-temp

Need output

server1
server2
server3
notfound server4
notfound server5_root
notfound server6_silver
server7
notfound server7-test
server7-temp

How come server7 is not found while server1, 2, and 3 are found? And, after several threads of yours with very similar topics, it would have been nice to find at least an idea for a solution from your side...

1 Like

Sorry i update the file server7 . Everytime i am getting new challenge on vlookup .

it works in forloop but awk is faster while checking the file

this is not exactly what you're after as I don't understand 100% how you derive the result, but it's a start:

awk -F'[-_]' 'FNR==NR{f2[$1];next}{print ($0 in f2)?$0:"notfound " $0}' file2 file1

Well, I don't think there's NEW challenges on vlookup (which, by the way, is an EXCEL or more generally, spread sheet function not available / applicable in *nix). They all are varieties of problems that have been solved for you recently, and you could juggle around with those to find a solution on your own, and post here if you're stuck.
Howsoever, how far would

awk '
FNR==NR {split ($1, T, "[_-]");
         SRV[T[1]]=$0
         next
        }
        {print (SRV[$1]?"":"notfound ") $0
        }

' file2 file1
server1
server2
server3
notfound server4
notfound server5_root
notfound server6_silver
server7
notfound server7-test
notfound server7-temp

get you?

1 Like

The following produces the output requested in post #1 from the two input files shown in post #1, but without a clear description explaining the logic that is supposed to be implemented, I have no idea if the actually implements what is desired:

awk -F'[_-]' '
FNR == NR {
	for(i = 1; i <= NF; i++) {
		tags[tag = tag $i]
		# printf("Added possible tag \"%s\" from \"%s\"\n", tag, $0)
		tag = substr($0, 1, length(tag) + 1)
	}
	tag = ""
	next
}
{	print (($0 in tags) ? "" : "notfound ") $0
}' file2 file1

As always, if you're running this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

that Don and RudiC. I can able to get the output from RudiC script itself