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 Ask from specific column from two files

Tags
awk, shell scripts, solved

👤 Login to reply

 
Thread Tools Search this Thread
# 8  
Old 03-21-2018
THis is original input file i need check the WWN from file1 and append the line if the WWn found. If not mark has notfound

Code:
Switch1, 381 12 45 F-Port 50:00:09:75:50:0d:bd:da
switch2, 8 8 3c0800 21:00:00:1b:32:12:8c:20
switch2, 9 9 3c0900 21:00:00:1b:32:9e:fe:ec
switch2, 10 10 3c0a00 21:00:00:24:ff:8b:e2:04
switch2, 12 12 3c0c00 21:00:00:24:ff:05:01:20
switch2, 13 13 3c0d00 21:00:00:24:ff:8b:e1:fe
switch3, 339 10 35 F-Port 50:00:09:75:00:0c:e9:d4
switch3, 340 10 36 F-Port 50:00:09:75:00:0c:e9:2c
switch3, 341 10 37 F-Port 50:00:09:75:00:0c:e9:6c
switch3, 342 10 38 F-Port 50:00:09:75:00:0c:e9:ac


New Input file was having like this

Code:
10.62.75.120, portIndex: 247 portName: slot12 port23,20:f1:0a:25:b5:03:02:90
10.62.75.120, portIndex: 247 portName: slot12 port23,20:50:00:2a:6a:00:b8:00 
10.62.75.120, portIndex: 247 portName: slot12 port23,20:50:00:2a:6a:00:b8:00 
10.62.75.120, portIndex: 247 portName: slot12 port23,21:00:00:24:ff:8b:e1:fe
10.62.75.120, portIndex: 247 portName: slot12 port23,20:50:00:2a:6a:00:b8:00

# 9  
Old 03-21-2018
No surprise if you change the structure of your files. Get rid of the FS=" " and report back.
# 10  
Old 03-22-2018
Quote:
Originally Posted by RudiC
No surprise if you change the structure of your files. Get rid of the FS=" " and report back.
I ran the script by removing FS=" " same output for all record it was updating not found.
# 11  
Old 03-22-2018
Code:
awk 'FNR == NR {T[$2] = $0; next} $0 = $0 "|" (T[$NF]?T[$NF]:"Notfound")' FS="," file1  file2
10.62.75.120, portIndex: 247 portName: slot12 port23,20:f1:0a:25:b5:03:02:90|alias:server1_00,20:f1:0a:25:b5:03:02:90
10.62.75.120, portIndex: 247 portName: slot12 port23,20:50:00:2a:6a:00:b8:00 |Notfound
10.62.75.120, portIndex: 247 portName: slot12 port23,20:50:00:2a:6a:00:b8:00 |Notfound
10.62.75.120, portIndex: 247 portName: slot12 port23,21:00:00:24:ff:8b:e1:fe|alias:server5_00,21:00:00:24:ff:8b:e1:fe
10.62.75.120, portIndex: 247 portName: slot12 port23,20:50:00:2a:6a:00:b8:00|Notfound

on Ubuntu 16.04.4 LTS with mawk 1.3.3 Nov 1996.
# 12  
Old 03-22-2018
thanks it resolved now.
# 13  
Old 04-06-2018
I used same code but it was not comparing

Code:
awk 'FNR == NR {T[$2] = $0; next} $0 = $0 "|" (T[$NF]?T[$NF]:"Notfound")' FS="," file1  file2

Code:
533,000A3 Server1_Parent                  000A3 00666   R1:13  RW RW RW  A..1.        0        0 RW  WD   Consistent
533,000A4 Server2_Silver                  000A4 007B6   R1:12  RW RW RW  A..1.        0        0 RW  WD   Consistent
533,000A5 Server2_Silver                  000A5 007B7   R1:12  RW RW RW  A..1.        0        0 RW  WD   Consistent
533,000A6 Server3_Parent                  000A6 007B8   R1:12  RW RW RW  A..1.        0        0 RW  WD   Consistent
533,000A7 Server3_Parent                  000A7 007B9   R1:12  RW RW RW  A..1.        0        0 RW  WD   Consistent

Device to compare File 1 with colume2
Quote:
000A3
000A2
000A3
000A4
Device to compare File2 with colume5
Code:
00666
000A2
007B7
000A4
007B9


Last edited by ranjancom2000; 04-06-2018 at 02:32 PM..
# 14  
Old 04-09-2018
sorry to bump any help on this
👤 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 non similar files ranjancom2000 Shell Programming and Scripting 6 04-18-2018 09:59 AM
Vlookup using Ask from specific column shell script ranjancom2000 Shell Programming and Scripting 10 11-29-2017 05:47 AM
Overwrite specific column in xml file with the specific column from adjacent line rk4k Shell Programming and Scripting 2 10-20-2015 05:00 AM
awk or sed to find specific column from different files Tzole Shell Programming and Scripting 3 01-29-2013 09:07 AM
Concatenating many files based on a specific column contents ks_reddy Shell Programming and Scripting 4 06-13-2012 04:18 AM
Divide data with specific column values into separate files chanclitas Shell Programming and Scripting 3 04-24-2012 08:14 PM
averaging specific column of multiple files ida1215 Shell Programming and Scripting 15 12-28-2011 12:20 PM
vlookup files dodasajan Shell Programming and Scripting 4 09-08-2011 04:16 AM
merge files like VLOOKUP godzilla07 Shell Programming and Scripting 3 11-30-2010 07:37 PM
Concatenate two files after a specific column sogi Shell Programming and Scripting 1 05-21-2009 11:10 PM


All times are GMT -4. The time now is 03:15 AM.

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