Code used to find the server from cloum 3 and update needtotakesnap
Output came from above command
awk 'NR==FNR{A[$1];next}$3 in A{$3 = "needtotakesnap " $3}1' /home/Others/active-server.txt /home/Others/all-server |grep server1
879 dummy server1_217_silver dummy 00870 TDEV 2071575
831 Tier1 needtotakesnap server1 dummy 0363C TDEV 172631
831 Tier1 server1_server2 dummy 035E2 RDF1+TDEV 1035788
831 Tier1 server1_server2 dummy 03600 RDF1+TDEV 1553681
831 Tier1 server1_server2 dummy 03641 RDF1+TDEV 34526
831 Tier1 server1_server2 dummy 036BA RDF1+TDEV 552420
831 nofast_Tier3 server1_new dummy 05862 TDEV 172631
But i need to find all the server in this list to update has "needtotakesnap". The awk script only vlookup exact match. Is it possible to update all the row where the server1 found
This will replace if $3 contains an active-server name (in a similar manor to grep).
I'm not really sure what the vlookup approximate logic is. If this doesn't suit can you be more specific on how you want to match.
awk '
NR==FNR{A[$1];next}
{ for(active_server in A)
if(index($3, active_server) > 0) {
$3 = "needtotakesnap " $3
break
}
}1' /home/Others/active-server.txt /home/Others/all-server
1 Like
Thanks it was working. How i can get update the active_server server list if the server not found from all-server list
chubler_xl:
This will replace if $3 contains an active-server name (in a similar manor to grep).
I'm not really sure what the vlookup approximate logic is. If this doesn't suit can you be more specific on how you want to match.
awk '
NR==FNR{A[$1];next}
{ for(active_server in A)
if(index($3, active_server) > 0) {
$3 = "needtotakesnap " $3
break
}
}1' /home/Others/active-server.txt /home/Others/all-server
---------- Post updated at 05:02 AM ---------- Previous update was at 02:35 AM ----------
Also Vlookup was not able to find the server if it is uppercase is it possible to lookup without case sensitive.
Can you be a bit more specific on your requirements here?
Best bet is it to convert both strings to lower case before using index:
awk '
NR==FNR{A[tolower($1)];next}
{ for(active_server in A)
if(index(tolower($3), active_server) > 0) {
$3 = "needtotakesnap " $3
break
}
}1' /home/Others/active-server.txt /home/Others/all-server