filter out the special paragraph including a keyword

Help with writing and playing macros

filter out the special paragraph including a keyword

Postby olol » Wed Jul 26, 2006 2:20 pm

How to write a macro to filter out (or keep ) the special
paragraph including a keyword?


I use UEStudio to analyze the output messages of a simulation.

the trace buffer are something like these:


-----------------------------------------------------------------------
** Event #8656. T= 12 (12.00s). Module #30 `rose.node[27]'
{{{{{ Node[27]: round(1) handleMessage:[28]-->[-1]:<MSG_SPT_DEGREE>
Node[27]:handleMessage(): delete msg }}}}}

** Event #8657. T= 21 (21.00s). Module #3 `rose.node[0]'
{{{{{ Node[0]: round(1) handleMessage:<PLAN_CHECK_ALIVE>
Node[0] remain energy = 1999.95
Node[0]:handleMessage(): delete msg }}}}}

** Event #8658. T= 21 (21.00s). Module #4 `rose.node[1]'
{{{{{ Node[1]: round(1) handleMessage:<PLAN_CHECK_ALIVE>
Node[1] remain energy = 1999.98
Node[1]:handleMessage(): delete msg }}}}}

-------------------------------------------------------------------------

In order to make things clear, I'd like to detele all the trivial messages.
For the above instance, all the messages contain "<PLAN_CHECK_ALIVE>".

only the following paragraph are kept:

=======================================================
** Event #8656. T= 12 (12.00s). Module #30 `rose.node[27]'
{{{{{ Node[27]: round(1) handleMessage:[28]-->[-1]:<MSG_SPT_DEGREE>
Node[27]:handleMessage(): delete msg }}}}}

=======================================================

How can I write a macro to achieve this work?

Say, given a keyword, "PLAN_CHECK_ALIVE", delete the whole paragraph (between
two space lines) which contain this keyword.
User avatar
olol
Newbie
 
Posts: 1
Joined: Tue Jul 25, 2006 11:00 pm

Re: filter out the special paragraph including a keyword

Postby Mofi » Thu Jul 27, 2006 5:14 am

Enable the macro property Continue if a Find with Replace not found for the following macro without any regular expression search.

InsertMode
ColumnModeOff
HexOff
Bottom
IfColNum 1
"
"
Else
"

"
EndIf
Top
TrimTrailingSpaces
Loop
Find MatchCase "PLAN_CHECK_ALIVE"
IfNotFound
ExitLoop
EndIf
Find MatchCase Up "** Event"
EndSelect
Key HOME
StartSelect
Find MatchCase Select "}}}}^p^p"
Delete
EndSelect
EndLoop
Bottom
Key BACKSPACE
Top

The macro first makes sure that the last line of the file is terminated with a CRLF and also adds an additional blank line after the last paragraph. This must be to delete also the last paragraph if it contains the word PLAN_CHECK_ALIVE.

Back at top of the file the trailing spaces are deleted to let the 3rd find always find the end of a paragraph without using a regular expression.

Inside the loop the first find searches for the keyword. If it is not found, the loop exits. If it is found, find upwards the start of the paragraph. Move the cursor to the start of the line and use a third find to select the whole paragraph and the empty line below and delete it.

Last the added blank line at bottom of the file is deleted.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4051
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: filter out the special paragraph including a keyword

Postby cwq2008119 » Sat Jul 29, 2006 7:40 am

hello, Mofi
i am a new learner.
can you explain more detail about what "^p^p"

in "Find MatchCase Select "}}}}^p^p"" means?
User avatar
cwq2008119
Newbie
 
Posts: 6
Joined: Wed Jul 19, 2006 11:00 pm

Re: filter out the special paragraph including a keyword

Postby Mofi » Sat Jul 29, 2006 3:16 pm

cwq2008119 wrote:can you explain more detail about what "^p^p"


It's described in help of UltraEdit/UEStudio in the article about the Find command and also the Replace command. I have already written several times that you shoud read the help articles! Read the manual! You just have to press the Help button in the find or replace dialog. Stop asking such questions!!!!!!!!!!!!!!
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4051
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros