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

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by ranjancom2000
ranjancom2000's Unix or Linux Image
ranjancom2000 ranjancom2000 is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 18 April 2018, 10:00 AM EDT
Posts: 130
Thanks: 21
Thanked 1 Time in 1 Post
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

Sponsored Links
    #9  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by ranjancom2000
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 19 April 2018, 5:49 AM EDT
Location: Aachen, Germany
Posts: 12,487
Thanks: 400
Thanked 3,867 Times in 3,556 Posts
No surprise if you change the structure of your files. Get rid of the FS=" " and report back.
Sponsored Links
    #10  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by ranjancom2000
ranjancom2000's Unix or Linux Image
ranjancom2000 ranjancom2000 is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 18 April 2018, 10:00 AM EDT
Posts: 130
Thanks: 21
Thanked 1 Time in 1 Post
Quote:
Originally Posted by RudiC View Post
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 Unix and Linux 3 Weeks Ago   -   Original Discussion by ranjancom2000
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 19 April 2018, 5:49 AM EDT
Location: Aachen, Germany
Posts: 12,487
Thanks: 400
Thanked 3,867 Times in 3,556 Posts


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.
Sponsored Links
    #12  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by ranjancom2000
ranjancom2000's Unix or Linux Image
ranjancom2000 ranjancom2000 is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 18 April 2018, 10:00 AM EDT
Posts: 130
Thanks: 21
Thanked 1 Time in 1 Post
thanks it resolved now.
Sponsored Links
    #13  
Old Unix and Linux 1 Week Ago   -   Original Discussion by ranjancom2000
ranjancom2000's Unix or Linux Image
ranjancom2000 ranjancom2000 is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 18 April 2018, 10:00 AM EDT
Posts: 130
Thanks: 21
Thanked 1 Time in 1 Post
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; 1 Week Ago at 02:32 PM..
Sponsored Links
    #14  
Old Unix and Linux 1 Week Ago   -   Original Discussion by ranjancom2000
ranjancom2000's Unix or Linux Image
ranjancom2000 ranjancom2000 is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 18 April 2018, 10:00 AM EDT
Posts: 130
Thanks: 21
Thanked 1 Time in 1 Post
sorry to bump any help on this
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
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
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 05:52 AM.