• Login
Community
  • Login

Compare a whole file with several files / a directory

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 2.7k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    Stephan R
    last edited by Sep 3, 2018, 12:30 PM

    I have a (hopefully) simple question as a new user of Notepad:
    Is it possible to compare a file (which contains a list of 20-50 names) with a whole directory of files?
    I know I can search single names/phrases with the “Search” function in several files or a directory, but i haven’t found a way to use a file as “source” from which the the parameters for the search are gained to look for in several other files. Is there a way to do so, or is there a plugin or another software that can help me?
    Thanks for your help!

    S 1 Reply Last reply Sep 3, 2018, 12:57 PM Reply Quote 0
    • S
      Scott Sumner @Stephan R
      last edited by Sep 3, 2018, 12:57 PM

      @Stephan-R

      That really isn’t something that Notepad++ could do…it takes its core function (text editing) to a new level (writing the novel). But maybe there is something that could be done if you describe your problem a bit more. For example, you say you want to compare a file with a bunch of other files, but I don’t think this is what you really want based upon your other description. Maybe show some short example of your “source” data and what one of these “several other files” data would look like? Then maybe the helpers here are in a better position to make suggestions.

      1 Reply Last reply Reply Quote 2
      • S
        Stephan R
        last edited by Sep 4, 2018, 6:04 AM

        Thanks Scott for your post,
        of course I can describe it a little more, even if - as you say - Notepad++ may not be helpful with that special problem:
        I want to maintain a statistic in order to record information in which location and how often soccer players have played.
        At the moment I have a bunch of txt-files from different locations (location A.txt, location B.txt,…) which contain person’s names. In that directory there will be continously more and larger files.

        Now, when I get a new text-file with the actual players of the actual day and location (my “source”), I want to compare that file (=all names) with all the other files in that named directory, so that I get the played locations and the number of played games as a result of that search.
        Of course you could do the search (name by name) 25 times, but it would sure be easier if you could search 25 names in one go. (:
        Thanks for any ideas!

        1 Reply Last reply Reply Quote 0
        • G
          guy038
          last edited by Sep 4, 2018, 11:45 AM

          Hello, @stephan-r, @scott-sumner and All,

          Stephan, here is a solution which should be close enough to your needs :-))

          So, let’s imagine that your file contains the 20 family names and forenames , below :

          Smith Oliver
          Jones Olivia
          TaylorGeorge
          Brown Amelia
          Williams Harry
          Wilson Emily
          Johnson Jack
          Davies Isla
          Robinson Jacob
          Wright Ava
          Thompson Noah
          Evans Jessica
          Walker Charlie
          White Isabella
          Roberts Muhammad
          Green Lily
          Hall Thomas
          Wood Ella
          Jackson Oscar
          Clarke Mia
          

          I built it, from the most common English surnames and given names, seen below :

          https://en.wikipedia.org/wiki/List_of_most_common_surnames_in_Europe

          https://en.wikipedia.org/wiki/List_of_most_popular_given_names

          Then :

          • Copy/paste this list in a new # N++ tab

          • Open the Replace dialog or hit the ( Ctrl + H ) shortcut

          • Use the regex S/R :

          SEARCH : (?-s)\R(?=\w)

          REPLACE |

          • Select the Regular expression search mode

          • Set the Wrap around option

          • Click on the Replace All button

          You should get the text :

          Smith Oliver|Jones Olivia|TaylorGeorge|Brown Amelia|Williams Harry|Wilson Emily|Johnson Jack|Davies Isla|Robinson Jacob|Wright Ava|Thompson Noah|Evans Jessica|Walker Charlie|White Isabella|Roberts Muhammad|Green Lily|Hall Thomas|Wood Ella|Jackson Oscar|Clarke Mia
          
          • Verify that this single line does not end with the | symbol

          • Add, at the beginning of this line :

            • The modifier (?i) if you prefer a case insensitive search

            • The modifier (?-i) if you prefer a case sensitive search

          Now :

          • Select the Find in Files tab ( or use the Ctrl + Shift + F ) shortcut

          • Enter the following regex S/R

          SEARCH (?i)Smith Oliver|Jones Olivia|TaylorGeorge|Brown Amelia|Williams Harry|Wilson Emily|Johnson Jack|Davies Isla|Robinson Jacob|Wright Ava|Thompson Noah|Evans Jessica|Walker Charlie|White Isabella|Roberts Muhammad|Green Lily|Hall Thomas|Wood Ella|Jackson Oscar|Clarke Mia

          REPLACE $0

          • Of course, fill the Filters and Directory fields, accordingly !

          • Click on the Find All button

          In the Find result panel, you should get all the lines of all the files containing any name of the complete list in the search regex

          For instance, with 3 test files, containing some names, I got the following results :

          Search "(?i)Smith Oliver|Jones Olivia|TaylorGeorge|Brown Amelia|Williams Harry|Wilson Emily|Johnson Jack|Davies Isla|Robinson Jacob|Wright Ava|Thompson Noah|Evans Jessica|Walker Charlie|White Isabella|Roberts Muhammad|Green Lily|Hall Thomas|Wood Ella|Jackson Oscar|Clarke Mia" (12 hits in 3 files)
            D:\@@\758\Test_1.txt (3 hits)
          	Line 1: Player : Smith Oliver ( 2018-06-16 )
          	Line 2: Player : Davies Isla  ( 2018-06-16 )
          	Line 3: Player : Thompson Noah ( 2018-07-07 )
            D:\@@\758\Test_2.txt (4 hits)
          	Line 1: Player : Jones Olivia ( 2018-07-07 )
          	Line 2: Player : Williams Harry ( 2018-05-12 )
          	Line 3: Player : Walker Charlie ( 2018-06-23 )
          	Line 4: Player : White Isabella ( 2018-06-23 )
            D:\@@\758\Test_3.txt (5 hits)
          	Line 1: Player : Jones Olivia ( 2018-05-12 )
          	Line 2: Player : TaylorGeorge ( 2018-07-07 )
          	Line 3: Player : Brown Amelia ( 2018-07-28 )
          	Line 4: Player : Roberts Muhammad ( 2018-06-23 )
          	Line 5: Player : Clarke Mia ( 2018-06-23 )
          

          Notes :

          • We do not need the Replace field at all. However, with the regex $0, it would replace any match by itself, if, unfortunately, you would hit the Replace in Files button and valid the replacement !

          • Beware that the maximum amount of characters, in the search zone, is 2046. So, as the above search is, only, 267 char long, this means that your complete list may contain up to 140 names, about, without any trouble :-))

          Best Regards,

          guy038

          S 1 Reply Last reply Sep 5, 2018, 12:15 PM Reply Quote 2
          • S
            Stephan R @guy038
            last edited by Sep 5, 2018, 12:15 PM

            Hi @guy038
            this is working perfectly! Many thanks for the work that you put in my special (and probably unique) query! You saved my day! ((:

            Best Regards,
            Stephan

            1 Reply Last reply Reply Quote 0
            2 out of 5
            • First post
              2/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors