• Login
Community
  • Login

Want to copy all from specific character to end of line of each line.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 5.2k 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.
  • G
    Gagana Gawesh Weerasinghe
    last edited by Sep 20, 2020, 9:29 AM

    i want to copy part of lines to another document.
    example:

    aaabbbdd|accddod|40adco458|ac46789|7jb
    bbccddd|dcaod9do|40dondoa|aodnl4|dan
    cdodnd|adcadldn|40aconda|adod|dan

    result: able to delete all except this.

    |40adco458|ac46789|7jb
    |40dondoa|aodnl4|dan
    |40aconda|adod|dan

    thank you…

    M 3 Replies Last reply Sep 20, 2020, 2:12 PM Reply Quote 0
    • M
      M Andre Z Eckenrode @Gagana Gawesh Weerasinghe
      last edited by Sep 20, 2020, 2:12 PM

      @Gagana-Gawesh-Weerasinghe

      Assuming your partial-line text to be copied always begins with |40 AND always continues to the end of the line AND there aren’t any lines WHICH DO NOT contain data to be copied, I would do this (but also seem to recall having seen some potentially worthy proposals for automatically selecting/copying multiple separate strings, which I haven’t tried yet):

      1. Copy all text which contains your target data to a new Notepad++ tab; Move cursor to top.

      2. Open Replace dialog (menu Search > Replace… or Ctrl+H); Make sure that In selection and Backward direction are unchecked, and that Search Mode is set to Regular Expressions.

      3. Use these strings for Find and Replace:

        Find = ^.*(\|40.*)$
        Replace = \1

      4. Click on Replace All.

      Breakdown:

      • ^ matches start of line
      • .* matches 0 or more characters (in this case all characters from start of line until |40)
      • (\|40.*) matches AND captures all characters from |40 to end of line
      • $ matches end of line

      \1 replaces everything that was matched on each line with only that which was captured (via (\|40.*)) on each line.

      1 Reply Last reply Reply Quote 1
      • M
        M Andre Z Eckenrode @Gagana Gawesh Weerasinghe
        last edited by Sep 20, 2020, 2:25 PM

        @Gagana-Gawesh-Weerasinghe

        Sorry, I forgot the final step:

        1. Copy text and paste to the other document of your choice.
        1 Reply Last reply Reply Quote 0
        • M
          M Andre Z Eckenrode @Gagana Gawesh Weerasinghe
          last edited by Sep 20, 2020, 3:43 PM

          @Gagana-Gawesh-Weerasinghe

          Here is a very handy Python script posted by @Scott-Sumner (thanks, Scott!), which allows you to copy all marked text, and requires installing the Python Script plugin for Notepad++. To use this method, here is what you should do instead of my first set of instructions above:

          1. Install Python Script plugin; After installation, go to menu Plugins > Python Script > New Script and type a suitable name for Scott’s script (I use CopyMarked.py).

          2. Copy all code for the script from Scott’s post to your new named script tab, and save.

          3. Switch back to your tab containing the text to be marked and copied.

          4. Open Mark dialog (menu Search > Mark… or Ctrl+M); Make sure that In selection and Backward direction are unchecked, Search Mode is set to Regular Expressions, . matches newline unchecked. Optional: Check Wrap around if you don’t want or need to worry about where the cursor is when you perform the following steps.

          5. Use string \|40.* for Find what; Click on Mark All.

          6. Close dialog and run the script from menu Plugins > Python Script > Scripts > CopyMarked (or whatever name you gave it).

          1 Reply Last reply Reply Quote 1
          • G
            Gagana Gawesh Weerasinghe
            last edited by Sep 20, 2020, 4:31 PM

            thank you very much for valuable instructions… this saved me from a lot of trouble… thank you again…

            1 Reply Last reply Reply Quote 0
            • A
              Alan Kilborn
              last edited by Sep 20, 2020, 6:40 PM

              @M-Andre-Z-Eckenrode said in Want to copy all from specific character to end of line of each line.:

              very handy Python script…which allows you to copy all marked text, and requires installing the Python Script plugin

              It appears that this ability might be “going native”, meaning no longer a need for a script to do it.
              See https://github.com/notepad-plus-plus/notepad-plus-plus/pull/8867
              It isn’t accepting in to the actual codebase yet as of this writing, so if you’d like to see that feature with “inside Notepad++” support, maybe comment at that site.
              For me, I’ve had that script set up for a long time, so it makes no difference to me.

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