• Login
Community
  • Login

How to highlight repeated words (multiple words repeated), in a Text file?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 2 Posters 4.1k 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.
  • K
    Ki An
    last edited by Ki An Sep 28, 2021, 1:08 PM Sep 28, 2021, 1:05 PM

    Problem: Example of Text file

    1. abc 
    2. bcd
    3. abc
    4. aeef
    5. bcd
    6. fgh
    

    I want abc repeated in line 1.and 3. & bcd repeated in line 2. and 5. to be highlighted
    highlighted Or marked with Different colour for each word… or same colour
    1st priority is to mark repeated words
    I dont know which words are repeated…
    I guess there may be 50 some different words…
    with each word repeated about 5 times…

    P 1 Reply Last reply Sep 28, 2021, 1:50 PM Reply Quote 0
    • P
      PeterJones @Ki An
      last edited by Sep 28, 2021, 1:50 PM

      @Ki-An ,

      marked with Different colour for each word

      Notepad++ doesn’t have that many highlight colors.

      If you select the whole word abc then right click and choose Style All Occurrences of Token > Using ##th Style, then you can get some of what you want, but there’s only 5 styles to choose from.

      913f0f8a-2065-49b0-8f6a-55e6ab6959ee-image.png

      I showed making abc one style and bcd a different style. But you cannot get 50 different colors.

      Please note that Settings > Preferences > Highlighting may affect whether you can style just whole words or whether it can be partial words or go across a word boundary, and the usermanual section on that page of settings describes what each of the settings mean. (Oh, a note: the manual hasn’t been updated yet: that setting box was renamed from “Mark All” to “Style All Occurrences of Token” in a version after v8.0; I need to check on that)

      Also, please understand that such styling is temporary, and is not saved anywhere in the file or in Notepad++ config files – so the next time you run Notepad++, those stylings will not be there. The Style … Token colors are just meant as a temporary highlight, not as something persistent or that can be distributed to others.

      K 1 Reply Last reply Sep 28, 2021, 2:03 PM Reply Quote 0
      • K
        Ki An @PeterJones
        last edited by Ki An Sep 28, 2021, 2:03 PM Sep 28, 2021, 2:03 PM

        @PeterJones Wow, quick reply…Thankyou…
        but still have a problem…
        its ok, if there isnt many different colour, and colouring is temporary…
        my priority is to colour them… even single colour
        but point is I dont know which words are repeated
        right click and style words, requires me to select word
        which I dont know!?
        any way to automatically recognize repeated words, and highlight them

        P 1 Reply Last reply Sep 28, 2021, 2:12 PM Reply Quote 0
        • P
          PeterJones @Ki An
          last edited by PeterJones Sep 28, 2021, 2:13 PM Sep 28, 2021, 2:12 PM

          @Ki-An ,

          If you did something like Search > Mark, with “Bookmark Line” checked and “Search Mode = Regular Expression”, and searched for (\b\w+\b)(?=(?s).*\1)

          8b6b6ede-2a62-4175-93e2-249fe57f9284-image.png

          What it’s doing is searching for any group of 2 or more word characters (letters, numbers, and underscore) with word boundaries around it (which is how I define a “word”), followed by anything followed by another instance of the same word. It will mark/highlight the first instance of each of those words, and also add the circle bookmark to the left.

          After these are marked, you can then use Search > Bookmark > Next/Previous Bookmark menu entries (or their keyboard shortcuts) to easily navigate between the matches bookmarked lines (that, the lines that contain matches). Once you are navigating, you could use the style-all-occurrences if you want to see all of that particular word or not (or just use the smart-highlighting which happens when you manually select the word)

          K 1 Reply Last reply Sep 28, 2021, 2:21 PM Reply Quote 1
          • K
            Ki An @PeterJones
            last edited by Sep 28, 2021, 2:21 PM

            @PeterJones said in How to highlight repeated words (multiple words repeated), in a Text file?:
            Wow Great, highlight with Navigation too…
            saved a lot of time… Thanks a-lot

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