Vlookup using awk non similar files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vlookup using awk non similar files
# 1  
Old 04-17-2018
Vlookup using awk non similar files

I need to vlookup and check the server not found.

Source file 1
Code:
server1
server2
server3
server4
server5_root
server6_silver
server7
server7-test
server7-temp

Source file 2

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

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


Last edited by ranjancom2000; 04-17-2018 at 09:41 AM..
# 2  
Old 04-17-2018
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...
This User Gave Thanks to RudiC For This Post:
# 3  
Old 04-17-2018
Quote:
Originally Posted by RudiC
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...
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

Last edited by Don Cragun; 04-17-2018 at 11:09 AM.. Reason: Fix ICODE tags; add ICODE tags; change AWK to awk.
# 4  
Old 04-17-2018
this is not exactly what you're after as I don't understand 100% how you derive the result, but it's a start:
Code:
awk -F'[-_]' 'FNR==NR{f2[$1];next}{print ($0 in f2)?$0:"notfound " $0}' file2 file1

# 5  
Old 04-17-2018
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
Code:
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?
This User Gave Thanks to RudiC For This Post:
# 6  
Old 04-17-2018
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:
Code:
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.
# 7  
Old 04-18-2018
that Don and RudiC. I can able to get the output from RudiC script itself
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to compare two files in UNIX using similar to vlookup?

Hi, I want to compare same column in two files, if values match then display the column or display "NA". Ex : File 1 : 123 abc xyz pqr File 2: 122 aab fdf pqr fff qqq rrr (1 Reply)
Discussion started by: hkoshekay
1 Replies

2. UNIX for Beginners Questions & Answers

Vlookup not using awk

Hi I just want again to ask for help on what command to use to vlookup f1 group name in "/etc/group" matching f3 of it to "/etc/passwd" f4. I do need to display group name in the output of /etc/passwd without using awk or NR==FNR command. thank you while IFS=: read -r f1 f2 f3 f4 f5 f6 f7... (4 Replies)
Discussion started by: joonisio
4 Replies

3. UNIX for Beginners Questions & Answers

Vlookup on 2 files - inserting vlookup command on another command

Hello, i am trying to print group name column(etc/group) on script (etc/passwd) since group name is not listed on etc/passwd columns. Im trying to do a vlookup. but i cant figure out how i can insert the vlookup command FNR==NR inside the print out command or the output. I also tried exporting... (2 Replies)
Discussion started by: joonisio
2 Replies

4. Shell Programming and Scripting

Vlookup using awk without exact match

Code used to find the server from cloum 3 and update needtotakesnap Output came from above command awk 'NR==FNR{A;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... (3 Replies)
Discussion started by: ranjancom2000
3 Replies

5. Shell Programming and Scripting

Vlookup using awk

Hi folks, awk 'NR==FNR {m=$0; next} $1 in m{$0=m} {print}' file2 file1 Works a charm for a vlookup type query, sourced from https://www.unix.com/shell-programming-and-scripting/215998-vlookup-using-awk.html However my column content has white spaces and numbers. Example file1 The Man... (6 Replies)
Discussion started by: pshields1984
6 Replies

6. Shell Programming and Scripting

awk cmd for vlookup in Mysql

Hi, Is there possible to do vlookup in Mysql one table from another table based on one column values and placed the data in same table? if it is possible in mysql itself pls share links for reference. Here is the ex: i need to vlookup the cus.id in table to and place the cus.name in 4th... (3 Replies)
Discussion started by: Shenbaga.d
3 Replies

7. Shell Programming and Scripting

awk script to perform an action similar to vlookup between two csv files in UNIX

Hi, I am new to awk/unix and am trying to put together an awk script to perform an action similar to vlookup between the two csv files. Here are the contents of the two files: File 1: Date,ParentID,Number,Area,Volume,Dimensions 2014-01-01,ABC,247,83430.33,857.84,8110.76... (9 Replies)
Discussion started by: Prit Siv
9 Replies

8. Shell Programming and Scripting

Vlookup using awk

Hello, I am trying to use vlookup (Excel function) using awk but there is some problem :( --file1-- ABC123 101F X1 A $P=Z X2 A $P=X X3 B $P=F X4 C $P=G MNK180 END --file2-- X1 A_t $P=Z X2 A_t $P=X X3 B_u $P=F X4 C_o $P=G (2 Replies)
Discussion started by: young
2 Replies

9. Shell Programming and Scripting

Computing the ratio of similar columns in the two files using awk script

Thanks Bartus11 for your help in the following code to compare the two files "t1" and "t2". awk 'NR==FNR{a=1;next}$2 in a{print $2}' t1 t2 First can anyone explain that what is the purpose of assigning a =1? Second, the current script is printing out the matched columns between the... (4 Replies)
Discussion started by: coder83
4 Replies

10. Shell Programming and Scripting

vlookup files

hi frnds i have 2 files. 1st is dddd and 2nd is ssss ==> dddd <==: 1,charit 2,gilhotra ==> ssss <==: 1,sajan 2,doda 3,hello and i want o/p ...mean join and vlookup both files sajan,charit (4 Replies)
Discussion started by: dodasajan
4 Replies
Login or Register to Ask a Question

Featured Tech Videos