Notepad++ search with "Bookmark line" option doesn't bookmark all the lines that match a multi-line regex, but only the first one - regex

I want to filter everything from a log that belongs to a particular user.
With the following pattern, and the ". matches newline" option enabled, I can match everything that I am looking for, but when I ask Notepad++ to bookmark these line so I can copy them, something strange happens.
([^\n]+)userB(.+?)(?=([0-9]{4}-[0-9]{2}-[0-9]{2}))
In front of line 2 and 8 I see a bookmark icon, but the lines: 3,4,5 and 9,10,11 are missing an icon, although they belong to the highlighted text.
Why does Notepad++ highlight the text, but doesn't place the bookmark correctly? And more importantly, how can I fix this?
Here is the log that I am using:
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message
2015-03-02 11:28:45,468 WARN application [http-0.0.0.0-8080-9] userB 12:2 some message
extra information
at some.classes.and.function(Filename.java:123)
at some.classes.and.function(Filename.java:123)
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message
2015-03-02 11:28:45,468 WARN application [http-0.0.0.0-8080-9] userB 12:2 some message
extra information
at some.classes.and.function(Filename.java:123)
at some.classes.and.function(Filename.java:123)
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message

The following will extract the information you want without using bookmarks and should work in Notepad++ version 6.9.1 onwards.
It assumes that the lines of extra information don't start with a digit.
It deletes the copied lines from the data file so work on a copy of the data file if you want to preserve it.
It is not very efficient because the switch tab command positions the cursor back at the start of a tab's text.
It duplicates the last match for userB. (A minor irritant!)
Description
1) Define shortcuts for switching to next & previous tabs
2) Open the data file with Notepad++
3) Open a new tab then go back to the data file tab
4) Define a macro `Cut User data. Paste in next tab`
5) Run the macro `Cut User data. Paste in next tab` on the data file to `end of file`
(It needs to be run once prior to running it in `Run a Macro Multiple Times`
because of a quirk of Notepad++)
Method
1) Settings Shortcut Mapper Main menu
Switch to previous document = Ctrl+Alt+Left
Switch to next document = Ctrl+Alt+Right
Close
2) Open data file with Notepad++
3) File New Ctrl+Alt+Left
4) Start Recording
Find Find what: .+ userB.+\r\n(\D.+\r\n)*
Search Mode = Regular expression
Find Next Alt+F4
Ctrl+X Ctrl+Alt+Right
Ctrl+End Ctrl+V Ctrl+Alt+Left
Stop recording
Save Current Recorded Macro
Name: Cut User data. Paste in next tab OK
5) Macro Cut User data. Paste in next tab
Run a Macro Multiple Times
Macro to run: Cut User data. Paste in next tab
Run until end of file = Yes
Run then when it has stopped Cancel

(Editted to be an answer.)
At least in the current version of Notepad++ the macro halts while the switch dialog box appears when using the macro solution and switching tabs.
You must first go to settings, MISC., document switcher, and disable both check boxes. This is at least true in v7.6.

Related

Find and replace in Visual Studio code in a selection

I have the following line in a file I'm editing in VSCode:
...............111.........111.............111..
I want to replace all .s with 0s. However, when I highlight the line and do a find/replace for .s, all the .s in the document are replaced, not just the ones in the line I've select, even when I toggle the "Find in selection" button. Is this a bug? In other editors, if I select a chunk of text and then do a find/replace, it will only find/replace matches within the selected block.
Below is a snippet that you should be able to reproduce the issue with. The ...............111.........111.............111.. line is inside the test_unicode function.
def test_simple2(self):
"""Simple CSV transduction test with empty fields, more complex idx, different pack_size.
100011000001000 ->
..........111....................111..........11111..........111..
"""
field_width_stream = pablo.BitStream(int('1000110001000001000', 2))
idx_marker_stream = pablo.BitStream(int('11101', 2))
pack_size = 4
target_format = TransductionTarget.JSON
csv_column_names = ["col1", "col2", "col3", "col4", "col5"]
pdep_marker_stream = pablo.BitStream(generate_pdep_stream(field_width_stream,
idx_marker_stream,
pack_size, target_format,
csv_column_names))
self.assertEqual(pdep_marker_stream.value, 63050402300395548)
def test_unicode(self):
"""Non-ascii column names.
Using UTF8. Hard coded SON boilerplate byte size should remain the same, column name
boilerplate bytes should expand.
100010010000000 ->
2 + 4 + 9 2 + 4 + 6 2 + 4 + 7
...............111.........111.............111..
"""
field_width_stream = pablo.BitStream(int('100010001000', 2))
idx_marker_stream = pablo.BitStream(1)
pack_size = 64
target_format = TransductionTarget.JSON
csv_column_names = ["한국어", "中文", "English"]
pdep_marker_stream = pablo.BitStream(generate_pdep_stream(field_width_stream,
idx_marker_stream,
pack_size, target_format,
csv_column_names))
self.assertEqual(pdep_marker_stream.value, 1879277596)
I'm using VSCode 1.12.2 in Ubuntu 16.04.
I was able to get it to work but the workflow is poor:
control + H to open Find/Replace
Select your line of text
Click the "Find in selection" icon to the right Alt L or ⎇ ⌘ L on macOS)
Enter your find and replace characters in their inputs
Click the Replace all icon
It works but you have to go through the workflow all over again for each new selection (except for CTR + H of course). BTW I have the exact same behavior in Sublime Text.
Could you go with a regExp to find your lines? Do they contain only .'s and 1's?
This is a more general answer for other users who come here just wanting to use basic find and replace functionality.
On Mac you can press Command + Option + F to open Find and Replace:
Alternatively, you can press Command + F to open Find and then click the little triangle on the left to show the Replace field:
From the VSCode devs:
We used to enable find in selection automatically when opening the
find widget with a selection, but it was too easy to trigger
accidentally and produced a lot of complaints. You probably want to
set "editor.find.autoFindInSelection": true which will make it work
the way you expect.
The VSCode GitHub issue has more details if anyone is interested.
EDIT: The autoFindInSelection option is available starting from VSCode 1.13. That version is currently in development (as of 6/7/2017), so this fix won't work until the new version is released.
I found the following workflow to be fairly painless:
Select text region with mouse or keyboard.
Ctrl+H to toggle find and replace
Alt+L to toggle find in selection
Ctrl+Alt+Enter to replace all (or enter to replace individually)
Since sometimes we might have similarly named things so you don't want to select everything, one of my favorites shortcut sequences is to select the next occurrence:
Use shift and arrows to highlight the term you want to match.
Use Ctrl + d to highlight the next occurrence of the term.
The Basic Editing in VS Code documentation page has some extremely useful variations on find and replace. One extremely useful shortcut is the Column (Box) Selection.
Just ran into this, my solution was to do
command + N to create a new file
paste my selection in there
do my find and replace operations on that while file
copy result back on top of my original selection
On Mac:
Select the text
Press command + shift + L
For mac
Press command + option + f to bring up this menu:
Press the little icon that has the arrow pointing at it above (3 horizontal bars)
Select the text you want to do a find and replace in, and enter the 'find' and 'replace' fields
Press this icon:
That's all!
In 2022, there's a bug to be wary of 🐛
There is a silent bug (I'll add more about this as I learn more about it). But sometimes find and replace within selection doesn't find the values, even if you can see them with your own eyes. This is dangerous because you could think you've replaced them all but it really hasn't.
So do these two things:
a visual check after doing a find and replace (to make sure it worked)
if vscode completely ignores you (and doesn't do the find and replace within selection after you've followed the above instructions), close the find and replace box by pressing the "x" in the corner, and retry the sequence of steps (it worked for me after closing and retrying).
Okay, this is really dumb, at first I felt really stupid when I finally found this, then I realized its just VS Code which has a bad interface.
The key is, there are TWO TOOLS here,
Search/Replace (the pane on the left at the top of the Explorer) and Find/Replace (which is a dialogue which opens when you press CTRL-F)
THESE ARE NOT THE SAME TOOL!!
SEARCH-REPLACE is a tool written for project-wide searches and
changes
FIND-REPLACE is a small dialogue best suited for more
surgical editing.
i.e. you should use FIND-REPLACE!
find replace window image with find-in-selection highlighted
Also, its SUPER IMPORTANT to follow these steps in the right order, or it doesn't give the expected results.
Press CTRL-F to open the find dialogue (usually opens in the top right)
press the little arrow to the right of the find field which opens the replace input field
ensure "find in selection" is turned off (i.e. not highlighted)
type in the fields the strings you want to search/replace
select the text you want to do a search/replace within.
Now press "find in selection" (or type ALT-L)
You should see only highlighting in the area you previously selected.
Now you can click either "replace all" (CTRL-ALT-ENTER) or line-by-line "replace" (ENTER)
I hope this helps.
My suggestion to VSC developers, there should be a refresh button so that after you have selected the area of interest, and you already have your find and replace strings defined, you can select a new region and click "refresh find" instead of needing to repeat steps 3 to 8.
For those where it still does not work, there is one step omitted in all of the above answers: Uncheck "Find in selection" if it is checked (which it probably is when you are struggling with it and in despair googled the problem, and then found this SO entry). Only then select the lines and then re-check "Find in selection".
For Ubuntu, highlight the lines where you want to make changes, press alt-L and then ctrl-H. Then type the name you want to replace and replacement name in the top right dropdown.
Or some combination of these actions depending on whether the dropdown is already open or you're already in alt-L mode. I'm still learning but thought I'd share what's working.

How to keep the view format in notepad++ from simple notepad?

Been trying to get this one done for some time and couldn't find a solution.
The annoying issue I got is that when I open my x.txt notepad file everything is in line, organized, well arranged however when I do open it with notepad++ everything gets messed up. Here is a quick example (left notepad++/right notepad, same file) http://prntscr.com/9ypxcm
Some of the files get the same view format and style in both notepad and notepad++ (probably they were created originally in notepad++?) however some of my other text documents get really messed into notepad++ and I just hate simple windows notepad when it comes to text editing.
Would appreciate some help. Thank you
I just checked for How much spaces does a tab takes in both ?.
Notepad++ takes 4 spaces to constitute 1 tab.
Windows Notepad takes 6 spaces to constitute 1 tab.
Therefore when a file which is first edited in Windows Notepad ( 6 spaces-tab ) is opened in Notepad++, the tab is converted to 4 spaces reducing 2 spaces. That's why everything gets messed up
Solution
1) This is same file opened in two editors.
2) Now go as directed
Settings --> Preferences --> Tab Settings --> normal.
Uncheck the Use default value.
Click on Tab size. A small input box will appear.Input 6 as value and press Enter.
3) The tabs are now properly formatted.

mutt - index search on yanked text

I'm wondering if there is anyway to "search" or "limit" in the mutt index based on text yanked from either an "edit" or "page" mode.
I'm trying to build a macro for the index, that when pressed will limit the index to only mail from (~f) the From: .*$ regex of the current item.
What this will help me to do is see the context of all the messages from a particular sender... it also helps when people accidentally "break threads" when they shouldn't.
I was hoping it would be similar to vim as discussed here and i could yank text from one area and then type ^R" to paste back into the "search" or "limit" prompt.
I tried to make a macro to go into edit and then search for the from string, but i can't figure out how to paste it back into anything in the index...
Here is an incomplete (and ugly) solution:
macro index O "|grep ^From | awk 'NR==1 {printf \"macro index Q l%s\",$2}' > /tmp/from;echo>>/tmp/from\n:source /tmp/from\nQ"
The O macro will extract the from address from the current message, and save a new macro definition to /tmp/from.
Then it will source that definition, and finally execute it.
Note: I'm having trouble adding newlines in the script (that's the reason for the echo>>, and the need for you to press enter at the end of the limit prompt. Will try to improve this.

Transpose function in Notepad++

I have a text file as:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
I want output as:
Line1: 0xC1,0x63,0x3F,0x01,
Line2: 0x80,0x00,0x80,0xA0,
How to do this using replace function in Notepad++?
You can use the below shortcuts to do the transpose in Notepad ++
Step 1: Ctrl + A: selects all.
Step 2: Ctrl + J: Transpose the Row you selected
Use the box select feature to select the second column text.
Use Alt+Shift+Arraw keys to select the second column.
Copy the selected text to a new file.
Use Find/Replace to remove all the newline characters.
Ctrl+F to open find/replace dialog box.
Select either Extended or Regular Expression Serach mode.
Type \r\n in Find What box.
Keep the Replace with box blank.
Click on Replace All in ALL Open Documents.
Now, the text is brought in single line.
Copy the text from second file and paste it to second line of first file.
Cheers...
There is no built-in function in Notepad++ for transposing a matrix and you can't do it using Replace (as M42 pointed out). Also, I'm not aware of any related plugin. So you will either need a different editor or do it with a script. The simplest solution I guess using a Spreadsheet, eg Excel or OpenOffice, both of them allow you to easily transpose a table.
But, there's still a good alternative without leaving Notepad++. Is to use the Python Script plugin.
Setup Python Script plugin
Install Python Script plugin, from Plugin Manager or from the official website.
When installed, go to Plugins > Python Script > New Script. Choose a filename for your new script (eg transpose.py) and copy the first code block that follows and copy the second one to another script, called for example transpose_uneven.py.
Open your data file and then run Plugins > Python Script > Scripts > transpose.py. This will open a new tab with your data transposed.
transpose.py
delimiter=","
newline="\n"
content=editor.getText()
matrix=[line.split(delimiter) for line in content.rstrip(newline).split(newline)]
transposed=list(map(list, zip(*matrix)))
notepad.new()
for line in transposed:
editor.addText(delimiter.join(line) + newline)
if len(transposed)!=len(matrix[0]):
console.clear()
console.show()
console.write("Warning: some rows are of uneven length. You might consider using the transpose_uneven script instead.")
transpose_uneven.py
import itertools
delimiter=","
newline="\n"
content=editor.getText()
matrix=[line.split(delimiter) for line in content.rstrip(newline).split(newline)]
transposed=list(map(list, itertools.izip_longest(*matrix, fillvalue="")))
notepad.new()
for line in transposed:
editor.addText(delimiter.join(line) + newline)
Examples
The transpose.py script will transpose the following example:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
To:
0xC1,0x63,0x3F,0x01
0x80,0x00,0x80,0xA0
,,,
If some of your rows are uneven:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
0x02
The uneven columns will be discarded accordingly:
0xC1,0x63,0x3F,0x01,0x02
If this is not desired, use transposed_uneven.py and it will return:
0xC1,0x63,0x3F,0x01,0x02
0x80,0x00,0x80,0xA0,
,,,,
If you really have such a fixed format and need such a fixed output i normally try it with an instant macro.
So my cursor is in the top left corner of the file ready to manipulate and i press the record button (or within the menu bar Macro - Start recording).
In you specific case now press:
End
Del
Pos1
↓
End hit the stop button (or within the menu bar Macro - Stop recording).
Now for a first test hit the playback button (or within the menu bar Macro - Playback) and test if it works. If yes click on Macro - Run a macro multiple times and select Run until the end of file.

Add trailing zeroes to line in notepad++

I have a file containing (hundreds) of blocks of numbers like below;
This one is fine (16x20, correct number of rows and columns)
11111111111111111110
16666616666666661110
16111616111111162610
16111646111663132610
16162616261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261626132610
16166313661116632610
16111111111116132610
16666666666666136610
11111111111111111110
This one needs to be padded with trailing zeroes so it is (16x20)
111111111111111111
166616666666663661
166611111111111661
166666366663661661
113161111111161611
1316166666616161
1616162262616161
11616166112616161
16616166116616161
16616162262616161
16616166266616161
16616111161116161
1661666666666616111
1661666166163366661
1641666166166613661
1111111111111111111
I would like to pad them with zeroes so they are all like the first example. I'm aware of the regular expressions feature in notepad++ but am struggling to get it to work. I appreciate any help given.
You could do it via a macro.
First append a large number of zeroes to the end of each line using a macro.
Caret on the first entry
click record macro
press end
type out 20 zeroes
press down arrow
click stop recording
play the macro until all lines look like this
11111111111111111100000000000000000000000000000000000000000000
16661666666666366100000000000000000000000000000000000000000000
16661111111111166100000000000000000000000000000000000000000000
16666636666366166100000000000000000000000000000000000000000000
11316111111116161100000000000000000000000000000000000000000000
131616666661616100000000000000000000000000000000000000000000
161616226261616100000000000000000000000000000000000000000000
1161616611261616100000000000000000000000000000000000000000000
1661616611661616100000000000000000000000000000000000000000000
1661616226261616100000000000000000000000000000000000000000000
1661616626661616100000000000000000000000000000000000000000000
1661611116111616100000000000000000000000000000000000000000000
166166666666661611100000000000000000000000000000000000000000000
166166616616336666100000000000000000000000000000000000000000000
164166616616661366100000000000000000000000000000000000000000000
111111111111111111100000000000000000000000000000000000000000000
Then...
Caret on first line
click record
press home key
press the right arrow key 20 times
hold shift and press end key
press delete key
press down arrow
click stop recording
play the macro until all lines are processed
You could save the entire process as a single macro so its just a single click in the future.
I can give you a macro solution
go to the beginning of your text
select Macro/Start Recording
press end, press 0 16 times then press Home and down arrow key
select Macro/End Recording
You now have a macro to add sixteen zeros to the end of all lines.
Playback this macro on all lines.
You now have appended zeroes to all lines.
Pressing Alt key and using mouse select the required block(columns) of text you want and paste it into another empty notepad tab
help on column mode editing is there inside notepad ? / help contents menu
Good luck
You can use the plugin ConyEdit to do this.
With ConyEdit running in the background, follow these steps:
use the command line cc.aal 00000000000000000000 to append after lines with twenty zero character.
use the command line cc.gc 1/\d{20}/ to get the first column of regex match.
Looking to do this manualy and not progomaticly ?
Open Findreplace
Copy from the last to rhe first WITHOUT NUMBERS on a line so...
in this example
111111111111111111 <---from here
to here ---> 166616666666663661
166611111111111661
paste that into the fine ( yes your effecticly copying the return wich some applications allow you to manualy input others wont )
then in the replace box, type '0' then your return
Hit that magic replace all :D
This will then add a 0 every time it hits a new line, then add a new... new line....
edit : quickly reviewing another method a second to recover for alternate options :P give me 10
edit 2:
Ah ok somthing like this will work :P just tested it.
use [0-9] in the find replace. so if im looking for 123123123123 ( wich is 12 long ) and i need to buff i up to 20,
Your FIND must be in ()
so..
the find would be
([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
and the replace is referd to as \1 no the regex, this was my mistake
\100000000
tested and confirmed !dont forget YOU NEED MATCH ALL on, WRAP off!
And so on for your other numbers, Not sure if you can loop this with macros nd stuff :P but hope it helps more than you have now
two good resources.
http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/comment-page-1/
http://regexpal.com/
base on OP's comment: you could try an editor called vim/gvim
open your file in vim, then type:
:%s/.*/\=printf("%-20s",getline("."))/|%s/ *$/\=substitute(submatch(0)," ","0","g")/
don't forget pressing <Enter> after the above typing.
then you will see the text has been changed into what you want.
of course vim macro can work as well, however, I feel command better... :)