If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Lookup between 2 files ( korn shell )

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-06, 22:12
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
Lookup between 2 files ( korn shell )

Hi All.,

i have a problem. I hope i can get some help on this issue here;
i have 2 txt files say file1 and file 2

file1 has;

WLMT:XXXXXXXX:cp
DOLR:YYYYYYY:ascii,unblock
WLG:TTTTTTT:dd:73:ascii,unblock
MARSSSSS:dd:152:ascii,unblock
GGG:QQQQQQQQQQ:112:ascii,unblock
EIE:CCCCCCCC:cp
WLL:MMMMMMMMM:wlg_dd.ksh
WWW:IIIIIIIIII:dd:160:ascii,unblock

FILE2 has;

QQQQQQ:WLMT:GGGG
REWWE:WLG:NNNN
FSSG:PPP:VVSSG
UIUIUOLR:CXZMZ
VSDSS:MAR:FFYFBB
VFJHSJ:KKK:VXBVS
CNXBCXC:QQQ:CBVCZ

FILE1 and FILE2 are : delimited files.

i have to do a lookup between the FILE1 and FILE2 based on the 1st column of FILE1 and 2ND column of FILE2 and then write the output i.e matches only to a txt file say any name like result.txt

i.e from FILE1 the 1st column WLMT
DOLR
WLG
MAR
GGG
EIE
WLL
WWW

with the 2nd column of FILE2 ; WLMT
WLG
PPP
DOLR
MAR
KKK
QQQ

those that matches only., the script has to write the ouput to a txt file such as result.txt

can anyone please help in this issue

Thanks
pavi
Reply With Quote
  #2 (permalink)  
Old 01-27-06, 11:35
hyperbole hyperbole is offline
Registered User
 
Join Date: Jan 2006
Posts: 32
Look at uniq.
Reply With Quote
  #3 (permalink)  
Old 01-27-06, 17:32
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
lookup between 2 files ( korn shell)

Hello

Thanks guys for your suggestions;

FILE1=/home/pavi/DS.txt
FILE2=/home/pavi/chain.txt

awk -F ":" '{print $1}' $FILE1 > f1.txt
awk -F " " '{print $2}' $FILE2 > f2.txt


DS.txt contains;

ALBD:xxxxx
FLN:yyyyyyy
WLG:ttttttt

chain.txt contain;

ECK: ECK: 331
ECK: ECK: 336
FED :FED :427
FIE :FIE: 212
FLN :FLN: 140
FLN :FLN :141
FMF: FMF: 183
FR1 :FR1: 303
FTT :FTT :423
GAT :GAT: 185
GEN :GEN: 396
GFY :GFY: 268
GIA :GIA: 228
GMD :GMD: 264
MIN: MIN: 158
MRO :MRO: 354
MY0 :MY0: 315
NCS :NCS: 390
OSC :ALBD: 377
OSC :ALBD :378
OSC: ALBD: 379
OSC ALBD 380
WLG :WLG :243
WLG: WLG: 244
WLG :WLG: 245
WLG :WLG :246
MAT: WLG :247

the result.txt has to look like this;


OSC :ALBD: 377
OSC :ALBD :378
OSC: ALBD: 379
FLN :FLN: 140
FLN :FLN :141
WLG :WLG :243
WLG: WLG: 244
WLG :WLG: 245
WLG :WLG :246
MAT: WLG :247

the script has to match the 1st column from DS.txt with the 2nd column of chain.txt and only those that matched, move all the corresponding 1st , 2nd and 3rd columns of chain.txt to a output file say result.txt

this is what i am trying to accomplish.

can anyone please help me ..

tx
pavi
Reply With Quote
  #4 (permalink)  
Old 02-12-06, 22:07
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Quote:
Originally Posted by pavan_test
Hello

Thanks guys for your suggestions;

FILE1=/home/pavi/DS.txt
FILE2=/home/pavi/chain.txt

awk -F ":" '{print $1}' $FILE1 > f1.txt
awk -F " " '{print $2}' $FILE2 > f2.txt


DS.txt contains;

ALBD:xxxxx
FLN:yyyyyyy
WLG:ttttttt

chain.txt contain;

ECK: ECK: 331
ECK: ECK: 336
FED :FED :427
FIE :FIE: 212
FLN :FLN: 140
FLN :FLN :141
FMF: FMF: 183
FR1 :FR1: 303
FTT :FTT :423
GAT :GAT: 185
GEN :GEN: 396
GFY :GFY: 268
GIA :GIA: 228
GMD :GMD: 264
MIN: MIN: 158
MRO :MRO: 354
MY0 :MY0: 315
NCS :NCS: 390
OSC :ALBD: 377
OSC :ALBD :378
OSC: ALBD: 379
OSC ALBD 380
WLG :WLG :243
WLG: WLG: 244
WLG :WLG: 245
WLG :WLG :246
MAT: WLG :247

the result.txt has to look like this;


OSC :ALBD: 377
OSC :ALBD :378
OSC: ALBD: 379
FLN :FLN: 140
FLN :FLN :141
WLG :WLG :243
WLG: WLG: 244
WLG :WLG: 245
WLG :WLG :246
MAT: WLG :247

the script has to match the 1st column from DS.txt with the 2nd column of chain.txt and only those that matched, move all the corresponding 1st , 2nd and 3rd columns of chain.txt to a output file say result.txt

this is what i am trying to accomplish.

can anyone please help me ..

tx
pavi
nawk -f pavi.awk DS.txt chain.txt > result.txt

pavi.awk:
Code:
BEGIN {
  FS="[ ]*:[ ]*"
}

FNR == NR {
   arr[$1]
   next
}

$2 in arr
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On