Vlookup using awk without exact match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vlookup using awk without exact match
# 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

This User Gave Thanks to Chubler_XL For This Post:
# 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 07: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 or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vlookup using awk without exact match for two colum input

Source file 1 335 R1-snapfound 0098F RDFType:R1 R2-Dev R2-snapfound ,010C0 RemoteSymmetrixID:345 335 R1-snapfound 00990 RDFType:R1 R2-Dev R2-snapfound ,010C1 RemoteSymmetrixID:345 335 R1-snapfound 009C0 RDFType:R1 R2-Dev R2-snapfound ,009C1 RemoteSymmetrixID:345 335 R1-snapfound 009C1... (5 Replies)
Discussion started by: ranjancom2000
5 Replies

2. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Help match the exact string

I just want to match "binutils1_test" only, and print the match line only lyang001@lyang001-OptiPlex-9010:/tmp$ cat file zbinutils1_test bbinutils1_test binutils1_test w-binutils1_test lyang001@lyang001-OptiPlex-9010:/tmp$ cat file |grep -w 'binutils1_test' ... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

4. Shell Programming and Scripting

Help with nawk (Exact Match)

I have a file with the contents below "lets say the name of the file is abcxyz" shown at the end of this. I am using nawk to find the exact ip address and the 6 lines after the match is found using the following nawk statement /usr/bin/nawk "/111.46.14.107/,printed==6 { ++printed; print; }"... (7 Replies)
Discussion started by: knijjar
7 Replies

5. Shell Programming and Scripting

Match exact Variable in Awk

I want to match exact string stored in Variable INO and print next two lines. I have written below code which partially matches: awk '/\'$VAR'/{getline; getline; print}' Will be thankful , if somebody can help in to resolve this problem. Please view this code tag video for how to use... (9 Replies)
Discussion started by: nitj
9 Replies

6. Shell Programming and Scripting

Exact match and #

Hi friends, i am using the following grep command for exact word match: >echo "sachin#tendulkar" | grep -iw "sachin" output: sachin#tendulkar as we can see in the above example that its throwinng the exact match(which is not the case as the keyword is sachin and string is... (6 Replies)
Discussion started by: neelmani
6 Replies

7. Shell Programming and Scripting

Exact match question

Hi, I have a file like follows . . . White.Jack.is.going.home Black.Jack.is.going.home Red.Jack.is.going.home Jack.is.going.home . . . when I make: cat <file> | grep -w "Jack.is.going.home" it gives: White.Jack.is.going.home Black.Jack.is.going.home Red.Jack.is.going.home... (4 Replies)
Discussion started by: salih81
4 Replies

8. Shell Programming and Scripting

exact string match ; search and print match

I am trying to match a pattern exactly in a shell script. I have tried two methods awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
Discussion started by: bash_in_my_head
8 Replies

9. Shell Programming and Scripting

Exact Word Match

I'm trying to find a exact word match but couldn't do it. ABC ABC_NE Searching for ABC_NE tried grep -w </ABC_NE/> grep "^ABC_NE$" but didn't worked , any awk variants would also help. ---------- Post updated at 08:40 AM ---------- Previous update was at 06:48 AM ---------- I... (2 Replies)
Discussion started by: dinjo_jo
2 Replies

10. UNIX for Advanced & Expert Users

can awk built-in "match" be exact??

hello everybody, as explained in the title, here is what I want: str1="name1 name2 name3" str2="name1" str3="name" I know that match(str1,str2) will return 1, but I want that match(str1,str3) returns 0 (when it also returns 1...) Is there a way to get that exact matching process done... (6 Replies)
Discussion started by: farphe
6 Replies
Login or Register to Ask a Question