Page 1 of 1

delete some lines contains same text but different num

PostPosted: Sun Jan 06, 2013 1:32 am
by payton
Hi!

I am a green hand to scripting.

I have written a script that filter some characters in a text file. The source characters are:

../../../External_delivery/TBSW/BasicSystem/api/bs_lib.h:869: warning: `struct sockaddr' declared inside parameter list
../../../External_delivery/TBSW/BasicSystem/api/bs_lib.h:869: warning: its scope is only this definition or declaration

After run script, the expected result is:

`struct sockaddr' declared inside parameter list
its scope is only this definition or declaration

UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.searchInColumn=false;
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll = true;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
UltraEdit.activeDocument.findReplace.replace("STRING", ""); //How can I write this STRING?

Thankful for all help I can get!

Payton

Re: delete some lines contains same text but different num

PostPosted: Sun Jan 06, 2013 11:29 am
by Mofi
If you add at top of the script the commands

UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.perlReOn();


to define the environment for the script completely and not depending on interal defaults of UltraEdit, the command for removing the file name and line number information and the warning message is:

UltraEdit.activeDocument.findReplace.replace("^.*?:\\d+:.*?: ", "");

^ ... start every search at beginning of a line.

.*? ... any character except new line characters zero or more times non greedy to next fixed character which is twice a colon.

\d+ ... any digit one or more times. (Backslash escaped by an additional backslash because of Javascript string.)


Alternatively you can use also

UltraEdit.activeDocument.findReplace.replace("^(?:.*?:){3} ", "");

^ ... start every search at beginning of a line.

(?:...) ... a non marking group.

.*? ... any character except new line characters zero or more times non greedy to next fixed character which is three times a colon.

{3} ... it must be possible to apply the expression inside the non marking group exactly 3 times.

Re: delete some lines contains same text but different num

PostPosted: Thu Jan 10, 2013 3:00 am
by payton
It works well. Thank u very much.