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



  • 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…



  • @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.



  • @Gagana-Gawesh-Weerasinghe

    Sorry, I forgot the final step:

    1. Copy text and paste to the other document of your choice.


  • @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).



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



  • @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.


Log in to reply