Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    92

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

  2. #2
    Join Date
    Jan 2006
    Posts
    32
    Look at uniq.

  3. #3
    Join Date
    Oct 2005
    Posts
    92

    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

  4. #4
    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> |
    +-----------------------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •