How to delete all lines not containing a specific word or a specific string or where a specific regular expression cannot find a string in the line?
Unix style if possible.
Thanks
Unix style if possible.
Thanks
Code: Select all
[images]http://...[/images]
Reply: [quotes]bla bla[/quotes]
[images]http://...[/images]
[quotes]bla bla[/quotes]
Code: Select all
InsertMode
ColumnModeOff
HexOff
Clipboard 9
ClearClipboard
Bottom
IfColNum 1
Else
"
"
EndIf
Top
Loop
Find "[images]"
IfFound
SelectLine
CopyAppend
Else
ExitLoop
EndIf
EndLoop
SelectAll
Paste
Top
ClearClipboard
Clipboard 0
This worked perfect for what I needed. Thanks.Mofi wrote:A quick manual solution is to simply search for the string of interest and check the advanced search option List Lines Containing String before executing the search. Then press button Clipboard to copy the lines of interest to the clipboard and close the dialog. Open a new file with Ctrl+N or select everything in current file with Ctrl+A and paste the clipboard content with Ctrl+V.
Also works. Two awesome ways to parse out the information I want. Thanks guys.pietzcker wrote:A Perl regular expression (courtesy of https://www.regular-expressions.info/completelines.html) that does the job is:
^(?:(?!%REGEX%).)*$\r\n
Replace all with nothing.
Code: Select all
InsertMode
ColumnModeOff
HexOff
SelectAll
Copy
NewFile
PreviousDocument
NextDocument
Paste
EndSelect
UnixReOff
Top
Find RegExp "%
"
Replace All ""
Bottom
Key END
IfColNum 1
Key BACKSPACE
EndIf
Bottom
IfColNumGt 1
InsertLine
IfColNumGt 1
DeleteToStartofLine
EndIf
EndIf
Top
Find RegExp "%*:*
"
Replace All ""
SelectAll
Clipboard 8
Copy
PreviousDocument
PerlReOn
Bottom
IfColNumGt 1
InsertLine
IfColNumGt 1
DeleteToStartofLine
EndIf
EndIf
Top
Find RegExp "^(?:(?!:).)*$\r\n"
Replace All ""
NextDocument
CloseFile NoSave
Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find RegExp "%
"
Replace All ""
Bottom
Key END
IfColNum 1
Key BACKSPACE
EndIf
Bottom
IfColNumGt 1
InsertLine
IfColNumGt 1
DeleteToStartofLine
EndIf
EndIf
Top
ColumnModeOn
ColumnInsert "½"
ColumnModeOff
Find RegExp "½^(*^):"
Replace All "^1:"
TrimTrailingSpaces
Top
Clipboard 9
ClearClipboard
Loop
Find RegExp "%½*^p"
IfFound
SelectLine
CutAppend
Else
ExitLoop
EndIf
EndLoop
NewFile
PreviousDocument
NextDocument
Paste
Top
Find "½"
Replace All ""
SelectAll
Cut
CloseFile NoSave
Else
Bottom
NextDocument
CloseFile NoSave
EndIf
Top
Clipboard 8
ClearClipboard
Loop
Find RegExp "%½*^p"
IfFound
SelectLine
CutAppend
Else
ExitLoop
EndIf
EndLoop
NewFile
PreviousDocument
NextDocument
Clipboard 8
Paste
Top
"
"
Top
Clipboard 9
Paste
Top
Find "½"
Replace All ""
SelectAll
Cut
CloseFile NoSave
You have replaced obviously both colons in the Perl regular expression string by @ instead of just the second formatted bold red in my previous post. The first colon has a special meaning in combination with the question mark. ?: immediately after and opening round bracket means: Do not mark (tag) the string found by the expression inside the round brackets. If you have replaced that colon also by @, you have created an invalid Perl regular expression.M@Cr0MaN wrote:I tried that with the Perl Expression and got a bunch of errors and it was still trying to find lines without colons.
That's the reason why all my macros in Mofis_Macro_Examples.uem contain at end (or above ExitMacro command) the comment lines.M@Cr0MaN wrote:After running pietzckers' Perl macro, a lot of the macro's I've made would not work anymore.
Code: Select all
// Activate UnixReOn or PerlReOn (v12+ of UE) here at the end of the macro
// if you do not use UltraEdit style regular expressions by default - see
// search configuration. Macro command UnixReOff sets the regular expression
// option to UltraEdit style.
// UnixReOn
// PerlReOn
From help of UltraEdit about macro command Loop: A value of 0 indicates Loop forever.M@Cr0MaN wrote:I also noticed you had a 0 after the word Loop. Why did you do that?
As you can see in the Column menu the menu item Insert/Fill Columns is disabled if Column Mode is not active as most other commands in the column menu. Therefore no special column command in a macro should be used without making sure that column mode is turned on during macro execution before using one of the special column commands.M@Cr0MaN wrote:I also noticed you added ColumnModeOn over ColumnInsert
You're absolutely right, Mofi. That's exactly what I did!Mofi wrote:You have obviously replaced both colons in the Perl regular expression string by @ instead of just the second formatted bold red in my previous post.
Right again this works GREAT! It will end up being a big time saver for quite a few of my slow macros! Many thanks for explaining this to me and giving me this sample! I feel kind of silly since I didn't continue to experiment and try just changing only one of the colons to @. Or actually I think I did try that but I changed the wrong one!Mofi wrote:Find RegExp "^(?:(?!@).)*$\r\n"
Oh, that's good to know. Thanks for the info, Mofi!Mofi wrote:That's the reason why all my macros in Mofis_Macro_Examples.uem contain at end (or above ExitMacro command) the comment lines ...
Oh, I see. That's kind of a relief to know.Mofi wrote:From help of UltraEdit about macro command Loop: A value of 0 indicates Loop forever ...
More good info! Thanks for that! :0 ) I guess it's easy to neglect stuff like this when it still works for you. But like I already mentioned, I want to make my macros compatible with all versions of UE, so I'll try to make sure I add column mode on to all the macros I have that use column insert, from now on! I think I already did that with most of my macros, but when I noticed it didn't really make any difference for my version of UE, I guess I got lazy. I know one thing for certain, if you forget to use columnModeOff, it can really screw up your Macro! I've made that mistake plenty of times in the past! but then again I've learned a lot through trial and error!Mofi wrote:As you can see in the Column menu the menu item Insert/Fill Columns is disabled if Column Mode is not active ...
This is good to know for certain. I have been unsure about this till now because of the double click bug that I have. It would automatically select lines even if I had used the command EndSelect and I guess that made me a little paranoid about making sure there was no selection after the paste command. But now that I know for certain that this is unnecessary, I won't use that command after the paste command anymore. And I totally agree with you about where I should have used EndSelect! Thanks Mofi, for taking the time to explain all this to me. You're lessons are much appreciated!Mofi wrote:EndSelect after pasting something into a new file is unnecessary...