how do replace multi-line to null

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

how do replace multi-line to null

Postby tanenbaum » Mon May 29, 2006 7:03 am

I wanna replace the following text as "nrmuser".gi_interface_s cmdbs04,only keep part of the first line and part of the last line.
but the following regular expression cann't find anything.
create table(.*)\p(.*\p)*.*cmdbs04

what's wrong with the expression?thanks a lot for your help.


create table "nrmuser".gi_interface_s
(
serial_id integer not null ,
int_id integer not null ,
port_no integer not null ,
ip_addr varchar(32),
ethernet_mode varchar(64),
timestamp datetime year to second,
first_result datetime year to second not null ,
compress_date date not null ,
s_month smallint not null ,
unique (compress_date,int_id,port_no) ,
unique (compress_date,serial_id)
)
fragment by expression
(s_month = 1 ) in cmdbs01 ,
(s_month = 2 ) in cmdbs02 ,
(s_month = 3 ) in cmdbs03 ,
(s_month = 4 ) in cmdbs04 ,
User avatar
tanenbaum
Newbie
 
Posts: 3
Joined: Thu Mar 09, 2006 12:00 am

Re: how do replace multi-line to null

Postby Mofi » Mon May 29, 2006 12:17 pm

I don't have much knowledge about Perl regex. But I think, \p is not allowed for Perl compatible regex. You have to use \r\n instead of \p.

However, it is nevertheless not working because the search string create table(.*)\r\n(.*\r\n)*.*cmdbs04 finds/selects the correct block but with the replace string \1cmdbs04 only the "create table" and the characters in the line with "cmdbs04" are removed. Don't know why.

But this macro works without any regex search or replace:

InsertMode
ColumnModeOff
HexOff
Loop
Find "create table "
IfNotFound
ExitLoop
EndIf
Delete
Key END
StartSelect
Find Select "cmdbs04"
EndSelect
Delete
"cmdbs04"
EndLoop
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: how do replace multi-line to null

Postby tanenbaum » Tue May 30, 2006 12:26 pm

thanks Mofi. the Macro did work. :-)
User avatar
tanenbaum
Newbie
 
Posts: 3
Joined: Thu Mar 09, 2006 12:00 am


Return to Find/Replace/Regular Expressions