How do I replace multiple lines

Find, replace, find in files, replace in files, regular expressions

How do I replace multiple lines

Postby scott » Fri May 14, 2004 12:18 am

First let me say you product is great there is no product like it I especially like the feature to convert encodings. Often I need to find one line of code and replace it with 10 how can i do this in Ultraedit
for example
Find
[php]define("_BWEL",[/php]
and replace with
[php]define("_ABR_MONDAY","Mon");
define("_ABR_TUESDAY","Tues");
define("_ABR_WEDNESDAY","Wed");
define("_ABR_THURSDAY", "Thurs");
define("_ABR_FRIDAY","Fri");
define("_ABR_SATURDAY","Sat");
define("_ABR_SUNDAY","Sun");

define("_BWEL",define("_BWEL",[/php]
User avatar
scott
Newbie
 
Posts: 1
Joined: Wed May 12, 2004 11:00 pm

Re: How do I replace multiple lines

Postby DanKirkd » Thu Jul 15, 2004 11:05 pm

Although it might seem a little ugly, one way to do this would be through the normal Replace dialog. Set Find What to:

define("_BWEL",

and Replace With to:

define("_ABR_MONDAY","Mon");^pdefine("_ABR_TUESDAY","Tues");^pdefine("_ABR_WEDNESDAY","Wed");^pdefine("_ABR_THURSDAY", "Thurs");^pdefine("_ABR_FRIDAY","Fri");^pdefine("_ABR_SATURDAY","Sat");^pdefine("_ABR_SUNDAY","Sun");^p^pdefine("_BWEL",define("_BWEL",

Note: the ^p that represent a line break.

Should do the trick.

Dan
User avatar
DanKirkd
Basic User
Basic User
 
Posts: 39
Joined: Wed Jul 14, 2004 11:00 pm

Re: How do I replace multiple lines

Postby JBWTB » Wed Jul 28, 2004 9:19 am

Hi

That works well and I've used it many times - for fixed lines.

Here's another problem - we have a machine that outputs files like

**StartProcess0
121231
123123
123
123
13
12312
123123
**End
**StartProcess1
etc

The data between StartProcess0 and **End has a variable number of lines.

So in some files there are say 2 lines between StartProcess0 and **End and other between 10-15

How can one select this random size paragraph between StartProcess0 and **End ?

The ^p approach does not work.
Tried stuff like StartProcess0 * ^p* End to no avail.
Thanks
JB
User avatar
JBWTB
Newbie
 
Posts: 2
Joined: Tue Jul 27, 2004 11:00 pm

Re: How do I replace multiple lines

Postby mrainey56 » Wed Jul 28, 2004 11:08 am

Here's one approach, using the contents of a template as the replace string and @@@ as dummy strings to mark the beginning and end of the text to replace. Could easily be put into a loop for multiple replacements (second example, not tested).

Or, you could just manually select the lines and insert a template, which would overwrite the selected text..




InsertMode
ColumnModeOff
HexOff
TrimTrailingSpaces
Find "StartProcess1"
Key HOME
Key DOWN ARROW
"@@@"
Key DOWN ARROW
Key HOME
Find "**End"
Key UP ARROW
Key END
"@@@"
Key HOME
Find Up "@@@"
Find Select "@@@"
Template 0


InsertMode
ColumnModeOff
HexOff
TrimTrailingSpaces
Loop
Find "StartProcess1"
IfNotFound
ExitLoop
EndIf
Key HOME
Key DOWN ARROW
"@@@"
Key DOWN ARROW
Key HOME
Find "**End"
Key UP ARROW
Key END
"@@@"
Key HOME
Find Up "@@@"
Find Select "@@@"
Template 0
EndLoop
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: How do I replace multiple lines

Postby JBWTB » Thu Jul 29, 2004 2:42 am

Hi

Thank you very much for that solution. It worked great.

I opened all the files (some 50) and ran the macro - edited to save and close after run - so it simply ran on 50 opened files.

Do you know of a way to run it on an amount of files without having to open them all at once i.e. processing them indivudually?


Best regards,
JB
User avatar
JBWTB
Newbie
 
Posts: 2
Joined: Tue Jul 27, 2004 11:00 pm


Return to Find/Replace/Regular Expressions