Identical content search between files of different names?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I do not know if it is possible to compare the contents of text files among other files in a second folder. I need the program to only search for matching strings and if it finds them, show both lines of the files with the matching string.



I have tried with diff but I do not get the result I expect.



An example of what I'm looking for is:



Assuming I have two folders and within each one are the text files I want to compare.



Folder1/test.txt:




example1 - A
exampleA - A
example2 - B
exampleB - C
example3 - C
exampleC - D


Folder2/test_different_name.txt:




exampleA - A
example3 - B
exampleB - C
exampleC - D
example1 - E


The result should be the matching strings of the compared files:



I added this bit as the formatting would not fit in a comment. If this is not the desired result, please delete it from the question! CharlesGreen



|==========================|
|String |File 1 |File 2 |
|--------------------------|
|example1 |A |E |
|example3 |C |B |
|==========================|


Note that only the matching texts are printed and when the entire line does not match, the differences are printed on the screen.









share|improve this question

























  • Does Meld is a good solution for you? It has file and directory comparison.

    – N0rbert
    Feb 10 at 16:14











  • @N0rbert I just tried it and it seems that it's not what I'm looking for. When the files have different names it does not show the content differences and is not able to track if there are other files with the same content. Also, for what I need, there will be a large amount of mismatched text and it would be a task that would take a lot of time.

    – MarianoM
    Feb 10 at 16:28













  • So, you are looking to find the lines in the files with the same first word, but different endings, and then show the lines from both files?

    – Charles Green
    Feb 10 at 17:12











  • @αғsнιη Try again :), it's true, my objective was not clear. What I hope is that instead of looking for strings of text from a text list, we search for strings of matching texts between the files in folders 1 and 2 and if there is identical text, the result will be printed indicating the file that contains the text.

    – MarianoM
    Feb 10 at 17:15






  • 1





    I added an edit to your question, if I have it wrong, please delete the edit.

    – Charles Green
    Feb 10 at 17:26


















0















I do not know if it is possible to compare the contents of text files among other files in a second folder. I need the program to only search for matching strings and if it finds them, show both lines of the files with the matching string.



I have tried with diff but I do not get the result I expect.



An example of what I'm looking for is:



Assuming I have two folders and within each one are the text files I want to compare.



Folder1/test.txt:




example1 - A
exampleA - A
example2 - B
exampleB - C
example3 - C
exampleC - D


Folder2/test_different_name.txt:




exampleA - A
example3 - B
exampleB - C
exampleC - D
example1 - E


The result should be the matching strings of the compared files:



I added this bit as the formatting would not fit in a comment. If this is not the desired result, please delete it from the question! CharlesGreen



|==========================|
|String |File 1 |File 2 |
|--------------------------|
|example1 |A |E |
|example3 |C |B |
|==========================|


Note that only the matching texts are printed and when the entire line does not match, the differences are printed on the screen.









share|improve this question

























  • Does Meld is a good solution for you? It has file and directory comparison.

    – N0rbert
    Feb 10 at 16:14











  • @N0rbert I just tried it and it seems that it's not what I'm looking for. When the files have different names it does not show the content differences and is not able to track if there are other files with the same content. Also, for what I need, there will be a large amount of mismatched text and it would be a task that would take a lot of time.

    – MarianoM
    Feb 10 at 16:28













  • So, you are looking to find the lines in the files with the same first word, but different endings, and then show the lines from both files?

    – Charles Green
    Feb 10 at 17:12











  • @αғsнιη Try again :), it's true, my objective was not clear. What I hope is that instead of looking for strings of text from a text list, we search for strings of matching texts between the files in folders 1 and 2 and if there is identical text, the result will be printed indicating the file that contains the text.

    – MarianoM
    Feb 10 at 17:15






  • 1





    I added an edit to your question, if I have it wrong, please delete the edit.

    – Charles Green
    Feb 10 at 17:26














0












0








0


1






I do not know if it is possible to compare the contents of text files among other files in a second folder. I need the program to only search for matching strings and if it finds them, show both lines of the files with the matching string.



I have tried with diff but I do not get the result I expect.



An example of what I'm looking for is:



Assuming I have two folders and within each one are the text files I want to compare.



Folder1/test.txt:




example1 - A
exampleA - A
example2 - B
exampleB - C
example3 - C
exampleC - D


Folder2/test_different_name.txt:




exampleA - A
example3 - B
exampleB - C
exampleC - D
example1 - E


The result should be the matching strings of the compared files:



I added this bit as the formatting would not fit in a comment. If this is not the desired result, please delete it from the question! CharlesGreen



|==========================|
|String |File 1 |File 2 |
|--------------------------|
|example1 |A |E |
|example3 |C |B |
|==========================|


Note that only the matching texts are printed and when the entire line does not match, the differences are printed on the screen.









share|improve this question
















I do not know if it is possible to compare the contents of text files among other files in a second folder. I need the program to only search for matching strings and if it finds them, show both lines of the files with the matching string.



I have tried with diff but I do not get the result I expect.



An example of what I'm looking for is:



Assuming I have two folders and within each one are the text files I want to compare.



Folder1/test.txt:




example1 - A
exampleA - A
example2 - B
exampleB - C
example3 - C
exampleC - D


Folder2/test_different_name.txt:




exampleA - A
example3 - B
exampleB - C
exampleC - D
example1 - E


The result should be the matching strings of the compared files:



I added this bit as the formatting would not fit in a comment. If this is not the desired result, please delete it from the question! CharlesGreen



|==========================|
|String |File 1 |File 2 |
|--------------------------|
|example1 |A |E |
|example3 |C |B |
|==========================|


Note that only the matching texts are printed and when the entire line does not match, the differences are printed on the screen.






search awk text diff






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 10 at 18:10









Charles Green

14.3k73960




14.3k73960










asked Feb 10 at 15:46









MarianoMMarianoM

7510




7510













  • Does Meld is a good solution for you? It has file and directory comparison.

    – N0rbert
    Feb 10 at 16:14











  • @N0rbert I just tried it and it seems that it's not what I'm looking for. When the files have different names it does not show the content differences and is not able to track if there are other files with the same content. Also, for what I need, there will be a large amount of mismatched text and it would be a task that would take a lot of time.

    – MarianoM
    Feb 10 at 16:28













  • So, you are looking to find the lines in the files with the same first word, but different endings, and then show the lines from both files?

    – Charles Green
    Feb 10 at 17:12











  • @αғsнιη Try again :), it's true, my objective was not clear. What I hope is that instead of looking for strings of text from a text list, we search for strings of matching texts between the files in folders 1 and 2 and if there is identical text, the result will be printed indicating the file that contains the text.

    – MarianoM
    Feb 10 at 17:15






  • 1





    I added an edit to your question, if I have it wrong, please delete the edit.

    – Charles Green
    Feb 10 at 17:26



















  • Does Meld is a good solution for you? It has file and directory comparison.

    – N0rbert
    Feb 10 at 16:14











  • @N0rbert I just tried it and it seems that it's not what I'm looking for. When the files have different names it does not show the content differences and is not able to track if there are other files with the same content. Also, for what I need, there will be a large amount of mismatched text and it would be a task that would take a lot of time.

    – MarianoM
    Feb 10 at 16:28













  • So, you are looking to find the lines in the files with the same first word, but different endings, and then show the lines from both files?

    – Charles Green
    Feb 10 at 17:12











  • @αғsнιη Try again :), it's true, my objective was not clear. What I hope is that instead of looking for strings of text from a text list, we search for strings of matching texts between the files in folders 1 and 2 and if there is identical text, the result will be printed indicating the file that contains the text.

    – MarianoM
    Feb 10 at 17:15






  • 1





    I added an edit to your question, if I have it wrong, please delete the edit.

    – Charles Green
    Feb 10 at 17:26

















Does Meld is a good solution for you? It has file and directory comparison.

– N0rbert
Feb 10 at 16:14





Does Meld is a good solution for you? It has file and directory comparison.

– N0rbert
Feb 10 at 16:14













@N0rbert I just tried it and it seems that it's not what I'm looking for. When the files have different names it does not show the content differences and is not able to track if there are other files with the same content. Also, for what I need, there will be a large amount of mismatched text and it would be a task that would take a lot of time.

– MarianoM
Feb 10 at 16:28







@N0rbert I just tried it and it seems that it's not what I'm looking for. When the files have different names it does not show the content differences and is not able to track if there are other files with the same content. Also, for what I need, there will be a large amount of mismatched text and it would be a task that would take a lot of time.

– MarianoM
Feb 10 at 16:28















So, you are looking to find the lines in the files with the same first word, but different endings, and then show the lines from both files?

– Charles Green
Feb 10 at 17:12





So, you are looking to find the lines in the files with the same first word, but different endings, and then show the lines from both files?

– Charles Green
Feb 10 at 17:12













@αғsнιη Try again :), it's true, my objective was not clear. What I hope is that instead of looking for strings of text from a text list, we search for strings of matching texts between the files in folders 1 and 2 and if there is identical text, the result will be printed indicating the file that contains the text.

– MarianoM
Feb 10 at 17:15





@αғsнιη Try again :), it's true, my objective was not clear. What I hope is that instead of looking for strings of text from a text list, we search for strings of matching texts between the files in folders 1 and 2 and if there is identical text, the result will be printed indicating the file that contains the text.

– MarianoM
Feb 10 at 17:15




1




1





I added an edit to your question, if I have it wrong, please delete the edit.

– Charles Green
Feb 10 at 17:26





I added an edit to your question, if I have it wrong, please delete the edit.

– Charles Green
Feb 10 at 17:26










1 Answer
1






active

oldest

votes


















2














Here you can do with awk as:



awk -F'-' 'NR == FNR { hold[$1]= $2; next } $2 != hold[$1] { print $1, hold[$1], $2 }' file1 file2
example3 C B
example1 A E


we are reading file1 into an awk associated array called hold with the key as first column and value from second column, where columns delimited by a hyphen we specified with awk's -F'-' option until the Number of Records is equal with File Number of Records - which it always true for first input file only, here file1.



then check column2 of file2 against the key with same first column we have saved in array, if those were different in second column, then we will print that.






share|improve this answer


























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1117169%2fidentical-content-search-between-files-of-different-names%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Here you can do with awk as:



    awk -F'-' 'NR == FNR { hold[$1]= $2; next } $2 != hold[$1] { print $1, hold[$1], $2 }' file1 file2
    example3 C B
    example1 A E


    we are reading file1 into an awk associated array called hold with the key as first column and value from second column, where columns delimited by a hyphen we specified with awk's -F'-' option until the Number of Records is equal with File Number of Records - which it always true for first input file only, here file1.



    then check column2 of file2 against the key with same first column we have saved in array, if those were different in second column, then we will print that.






    share|improve this answer






























      2














      Here you can do with awk as:



      awk -F'-' 'NR == FNR { hold[$1]= $2; next } $2 != hold[$1] { print $1, hold[$1], $2 }' file1 file2
      example3 C B
      example1 A E


      we are reading file1 into an awk associated array called hold with the key as first column and value from second column, where columns delimited by a hyphen we specified with awk's -F'-' option until the Number of Records is equal with File Number of Records - which it always true for first input file only, here file1.



      then check column2 of file2 against the key with same first column we have saved in array, if those were different in second column, then we will print that.






      share|improve this answer




























        2












        2








        2







        Here you can do with awk as:



        awk -F'-' 'NR == FNR { hold[$1]= $2; next } $2 != hold[$1] { print $1, hold[$1], $2 }' file1 file2
        example3 C B
        example1 A E


        we are reading file1 into an awk associated array called hold with the key as first column and value from second column, where columns delimited by a hyphen we specified with awk's -F'-' option until the Number of Records is equal with File Number of Records - which it always true for first input file only, here file1.



        then check column2 of file2 against the key with same first column we have saved in array, if those were different in second column, then we will print that.






        share|improve this answer















        Here you can do with awk as:



        awk -F'-' 'NR == FNR { hold[$1]= $2; next } $2 != hold[$1] { print $1, hold[$1], $2 }' file1 file2
        example3 C B
        example1 A E


        we are reading file1 into an awk associated array called hold with the key as first column and value from second column, where columns delimited by a hyphen we specified with awk's -F'-' option until the Number of Records is equal with File Number of Records - which it always true for first input file only, here file1.



        then check column2 of file2 against the key with same first column we have saved in array, if those were different in second column, then we will print that.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 10 at 22:57









        Charles Green

        14.3k73960




        14.3k73960










        answered Feb 10 at 18:41









        αғsнιηαғsнιη

        25k23100162




        25k23100162






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1117169%2fidentical-content-search-between-files-of-different-names%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Human spaceflight

            Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

            File:DeusFollowingSea.jpg