Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Unanswered: Compare two files word by word

    I need to compare two files word by word using unix korn shell scripting.

    Could someone help me? I need the code which will compare the 1st word from file1 with 1st word from file2,
    2nd word from file1 with 2nd word from file2 etc..., for all the lines.




    OS Details:

    SunOS apsomg00 5.8 Generic_117350-39 sun4u sparc SUNW,Sun-Fire-V240


    Data1:

    aaa bbb ccc
    dddd yyy hij

    Data2:

    aaa bcd edgf
    xxx yyy kkh

    I need to compare word by word the two files as below


    Expected output:
    ---------------

    aaa==aaa


    bbb==bcd
    if no
    append it to output file with the line number

    ccc==edgf
    if no
    append it to output file with the line number

    dddd==xxx
    if no
    append it to output file with the line number

    yyy==yyy

    hij==kkh
    if no
    append it to output file with the line number

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Does the input file have more than one word per line?

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Do both files have the same number of lines?
    If so, being really lazy, and assuming that this is not a production job:
    Code:
    nl file1 >file1nl
    nl file2 >file2nl
    diff file1nl file2nl >diff.list

Posting Permissions

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