Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Vlookup using awk without exact match

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-10-2018   -   Original Discussion by ranjancom2000
ranjancom2000's Unix or Linux Image
ranjancom2000 ranjancom2000 is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 8 May 2018, 2:13 PM EDT
Posts: 134
Thanks: 23
Thanked 1 Time in 1 Post
Vlookup using awk without exact match

Code used to find the server from cloum 3 and update needtotakesnap

Output came from above command


Code:
awk 'NR==FNR{A[$1];next}$3 in A{$3 = "needtotakesnap " $3}1' /home/Others/active-server.txt /home/Others/all-server |grep server1



Code:
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
Sponsored Links
    #2  
Old Unix and Linux 04-10-2018   -   Original Discussion by ranjancom2000
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 22 May 2018, 7:27 PM EDT
Posts: 3,527
Thanks: 154
Thanked 1,258 Times in 1,152 Posts
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.



Code:
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

The Following User Says Thank You to Chubler_XL For This Useful Post:
ranjancom2000 (04-12-2018)
Sponsored Links
    #3  
Old Unix and Linux 04-12-2018   -   Original Discussion by ranjancom2000
ranjancom2000's Unix or Linux Image
ranjancom2000 ranjancom2000 is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 8 May 2018, 2:13 PM EDT
Posts: 134
Thanks: 23
Thanked 1 Time in 1 Post
Thanks it was working. How i can get update the active_server server list if the server not found from all-server list

Quote:
Originally Posted by Chubler_XL View Post
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.



Code:
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 ----------

Quote:
Originally Posted by ranjancom2000 View Post
Thanks it was working. How i can get update the active_server server list if the server not found from all-server list

Also Vlookup was not able to find the server if it is uppercase is it possible to lookup without case sensitive.

Last edited by ranjancom2000; 04-12-2018 at 06:31 AM..
    #4  
Old Unix and Linux 04-17-2018   -   Original Discussion by ranjancom2000
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 22 May 2018, 7:27 PM EDT
Posts: 3,527
Thanks: 154
Thanked 1,258 Times in 1,152 Posts
Quote:
Originally Posted by ranjancom2000 View Post
Thanks it was working. How i can get update the active_server server list if the server not found from all-server list
Can you be a bit more specific on your requirements here?

Quote:
Originally Posted by ranjancom2000 View Post
Also Vlookup was not able to find the server if it is uppercase is it possible to lookup without case sensitive.
Best bet is it to convert both strings to lower case before using index:



Code:
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

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk to update file based on partial match in field1 and exact match in field2 cmccabe Shell Programming and Scripting 2 03-01-2017 07:17 AM
Vlookup using awk young Shell Programming and Scripting 2 02-13-2013 01:14 AM
Match exact Variable in Awk nitj Shell Programming and Scripting 9 06-28-2012 02:50 PM
exact string match ; search and print match bash_in_my_head Shell Programming and Scripting 8 05-22-2010 11:41 PM
can awk built-in "match" be exact?? farphe UNIX for Advanced & Expert Users 6 01-14-2009 09:29 AM



All times are GMT -4. The time now is 04:29 PM.