Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2003
    Posts
    71

    Unanswered: to find a match between two files

    I am trying to read two files and want to display

    if (field1 of file2) == (field2 of file1) then
    echo (file2:field1,2,3) (file1:field1)
    endif

    =================================================


    fille1 : clist
    DC DOBS DOBSON
    NE NXTP NEXTEL
    XE NXTL NEXTEL
    SP SPPCS SPPCS
    SP SPRNT SPRINT
    VW VZW VZW
    VZ VERIZ VERIZON
    TG TGTEL TGTEL
    TT TRTEL TRITEL
    WW WWPCS WWPCS
    EK EKN EKN
    TM TMOB TMOBILE
    AW ACIW ACIW

    fille2 :ilist
    aciw jefferson ne
    aciw saline ne
    aciw clay ne
    aciw gage ne
    aciw nemaha ne
    wwpcs saline ne
    wwpcs jefferson ne
    wwpcs gage ne
    wwpcs nemaha ne
    nxtp gage ne
    trtel hardin ky
    trtel barren ky
    nxtp boyd ky
    nxtp pulaski ky
    nxtp crawford pa
    nxtp chautauqua ny
    vzw chautauqua ny
    nxtp woodford ky
    nxtp rowan ky
    nxtp garrard ky
    nxtp jessamine ky
    nxtp laurel ky
    nxtp allen ky
    nxtp hardin ky
    nxtp taylor ky
    dobs crawford pa
    vzw crawford pa
    attws crawford pa
    dobs adair ky
    dobs garrard ky
    dobs laurel ky
    dobs green ky
    dobs chautauqua ny
    nxtl fayette ky
    sppcs fayette ky
    attws fayette ky
    attws woodford ky
    attws boyd ky
    attws carter ky
    attws jessamine ky
    aciw boyd ky
    aciw carter ky
    nxtp carter ky
    sppcs chautauqua ny
    sppcs hardin ky

    =================================================


    // here is how i have managed to display, is therebetter way to do this ? may be in awk.or else..
    cat findmatch.sh
    ================
    #set -xv
    while read x y z
    X=`echo $x|tr '[a-z]' '[A-Z]'`
    do
    #
    while read c1 c2 c3
    do
    if [ "$X"="$c2" ]
    then
    echo $z $y $x $c2|tr '[a-z]' '[A-Z]'
    else
    break;
    fi
    done < clist
    #
    done < ilist

    also extra spacing between if conditions creates problem here , does this only happen in korn shell?

  2. #2
    Join Date
    May 2004
    Location
    Barcelona, Spain
    Posts
    54
    You can read clist and ilist at the same time, thus not reading clist more than once. You should sort both files by the compared fields.
    There's a thread that covers this issue called "Merging files in a single one", dated May 25th. You can follow that for help!

    Also, if you have access to MySQL, you can import both files into two tables and let sql do work for you. I suppose this is slower, anyway.

    Hope this helps you

    Regards

    Iñaki

  3. #3
    Join Date
    Sep 2003
    Posts
    71
    Thanks for quick reply. i will see the post.
    i have these files on HP-unix and i am not using any DBMS.

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    something like this in awk

    nawk -f skd.awk file1 file2

    Code:
    FNR == NR {
      f1[toupper($2)]=$1
      next;
    }
    
    toupper($1) in f1 { print $0, f1[toupper($1)] }

  5. #5
    Join Date
    Sep 2003
    Posts
    71
    Thank you vgresh99.

    I am not much familiar with awk. what is file sdk.awk for in your solution?

  6. #6
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    sdk.awk is a file containing the 'Code' in the post.

  7. #7
    Join Date
    Sep 2003
    Posts
    71
    duh??? me...

    Is nawk system specific?

  8. #8
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    might be. What OS are you on?
    Try 'awk' [or gawk] if you don't have 'nawk'.

  9. #9
    Join Date
    Sep 2003
    Posts
    71
    BTW i am using HP-UX so only awk here.
    Thanx

  10. #10
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    ok, so try awk

Posting Permissions

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