delete some lines contains same text but different num

Help with writing and running scripts

delete some lines contains same text but different num

Postby payton » Sun Jan 06, 2013 1:32 am

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
payton
Newbie
 
Posts: 2
Joined: Sun Jan 06, 2013 1:05 am

Re: delete some lines contains same text but different num

Postby Mofi » Sun Jan 06, 2013 11:29 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: delete some lines contains same text but different num

Postby payton » Thu Jan 10, 2013 3:00 am

It works well. Thank u very much.
payton
Newbie
 
Posts: 2
Joined: Sun Jan 06, 2013 1:05 am


Return to Scripts