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|danresult: able to delete all except this.
|40adco458|ac46789|7jb
|40dondoa|aodnl4|dan
|40aconda|adod|danthank you…
-
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):-
Copy all text which contains your target data to a new Notepad++ tab; Move cursor to top.
-
Open
Replace
dialog (menuSearch > Replace…
orCtrl+H
); Make sure thatIn selection
andBackward direction
are unchecked, and thatSearch Mode
is set toRegular Expressions
. -
Use these strings for
Find
andReplace
:Find
=^.*(\|40.*)$
Replace
=\1
-
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. -
-
Sorry, I forgot the final step:
- Copy text and paste to the other document of your choice.
-
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:
-
Install Python Script plugin; After installation, go to menu
Plugins > Python Script > New Script
and type a suitable name for Scott’s script (I useCopyMarked.py
). -
Copy all code for the script from Scott’s post to your new named script tab, and save.
-
Switch back to your tab containing the text to be marked and copied.
-
Open
Mark
dialog (menuSearch > Mark…
orCtrl+M
); Make sure thatIn selection
andBackward direction
are unchecked,Search Mode
is set toRegular Expressions
,. matches newline
unchecked. Optional: CheckWrap around
if you don’t want or need to worry about where the cursor is when you perform the following steps. -
Use string
\|40.*
forFind what
; Click onMark All
. -
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.