Home Man
Search
Today's Posts
Register

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

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 04-10-2018
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
# 2  
Old 04-10-2018
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)
# 3  
Old 04-12-2018
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
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
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 04-17-2018
Quote:
Originally Posted by ranjancom2000
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
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

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Vlookup using awk without exact match for two colum input ranjancom2000 Shell Programming and Scripting 5 04-17-2018 07:55 AM
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
Grep exact match Cludgie Shell Programming and Scripting 2 05-06-2015 09:44 AM
Get the exact match of the string! dips_ag Shell Programming and Scripting 3 02-18-2015 01:51 PM
Help with nawk (Exact Match) knijjar Shell Programming and Scripting 7 12-05-2014 05:42 PM
Exact match question yuejian UNIX for Dummies Questions & Answers 11 10-12-2014 03:21 PM
Exact match using sed Kanja Shell Programming and Scripting 7 02-01-2014 03:57 AM
Exact match and # neelmani Shell Programming and Scripting 6 06-10-2012 10:06 AM
exact string match ; search and print match bash_in_my_head Shell Programming and Scripting 8 05-22-2010 11:41 PM
Exact Word Match dinjo_jo Shell Programming and Scripting 2 10-13-2009 01:25 AM


All times are GMT -4. The time now is 05:21 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password