Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: how to compare two text files to get the identical lines

  1. #1
    Join Date
    Sep 2008
    Beans
    9

    Question how to compare two text files to get the identical lines

    Hi,there.I am asking for help here.I get two text files of products number.I need to compare the 2 files to get the identical products number.

    The two files are attached below here.
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2006
    Beans
    578
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: how to compare two text files to get the identical lines

    There is a command called "diff" which will show the differences between two files, if that helps at all. The syntax, I believe, is:

    diff file1.txt file2.txt

    I hope this gets you on track, at least!

  3. #3
    Join Date
    Jun 2006
    Beans
    578
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: how to compare two text files to get the identical lines

    ... also, if you use the -y modifier, it will display the files side by side, which would help you see the similarities.

  4. #4
    Join Date
    Sep 2008
    Beans
    9

    Re: how to compare two text files to get the identical lines

    Quote Originally Posted by mjpatey View Post
    ... also, if you use the -y modifier, it will display the files side by side, which would help you see the similarities.
    hi,mjpatey.Thx.And the advice doesn't work for my problem here.

  5. #5
    Join Date
    Aug 2008
    Location
    WA
    Beans
    2,186
    Distro
    Ubuntu

    Re: how to compare two text files to get the identical lines

    Code:
    cat file1.txt|sed s/\"//g |awk -F\- '{print "grep "$2 " file2.txt"}' |sh >> dups.txt
    Last edited by iponeverything; November 10th, 2008 at 05:11 AM. Reason: didn't look at the text files.

  6. #6
    Join Date
    Jun 2006
    Beans
    578
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: how to compare two text files to get the identical lines

    OK. Sorry, gave it my best shot! After some searching, I don't see a command to do exactly what you're asking. But you could try the manpage for diff:

    Code:
     man diff
    and see if any of the options would get you close.

  7. #7
    Join Date
    Aug 2008
    Location
    Brazil
    Beans
    12,497
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: how to compare two text files to get the identical lines

    You could use "Meld" from the repositories. It is a very nice GUI diff tool, that highlight different lines from both files.

  8. #8
    Join Date
    Sep 2008
    Beans
    9

    Re: how to compare two text files to get the identical lines

    Quote Originally Posted by iponeverything View Post
    Code:
    cat file1.txt|sed s/\"//g |awk -F\- '{print "grep "$2 " file2.txt"}' |sh >> dups.txt

    Thank you,iponeverything.I am done with the problem after the command issued.And thank you all.May GNU-Linux be with you.

  9. #9
    Join Date
    Sep 2008
    Beans
    9

    Re: how to compare two text files to get the identical lines

    Quote Originally Posted by honglou View Post

    Thank you,iponeverything.I am done with the problem after the command issued.And thank you all.May GNU-Linux be with you.
    hi,iponeverything.Thank you for your nice and kind advice.
    And I still get a problem here since I am not famillar with the commands of 'sed' or 'awk'.I want to check out the products number in file2 ,but not in file1 which are products already on the website.So after the comparison,i would update the the website with the missing products.
    I wish you would get time and trouble to help me.Thank you in advance!

  10. #10
    Join Date
    Aug 2008
    Location
    WA
    Beans
    2,186
    Distro
    Ubuntu

    Re: how to compare two text files to get the identical lines

    Quote Originally Posted by honglou View Post
    hi,iponeverything.Thank you for your nice and kind advice.
    And I still get a problem here since I am not famillar with the commands of 'sed' or 'awk'.I want to check out the products number in file2 ,but not in file1 which are products already on the website.So after the comparison,i would update the the website with the missing products.
    I wish you would get time and trouble to help me.Thank you in advance!
    Not quite sure what your asking.You need the product numbers uniq to file2?

    If that is the case then just do:


    Code:
    diff dups.txt file2.txt| grep \> |sed s/\>//g |sed s/\"//g|awk '{print "\"HJ-"$1"\""}' > uniq-to-file2.txt
    Last edited by iponeverything; November 10th, 2008 at 03:09 PM.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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