Merging lines with continuation character and doing replacem

General discussions about Advanced Find and Replace
Post Reply
pelletic
Posts: 4
Joined: Mon Jan 31, 2005 5:32 pm

Merging lines with continuation character and doing replacem

Post by pelletic »

1) How can I merge lines that have an &, then find if 2 words exists to then replace 3 words?
Original string:
SUBFILE EMF147.PUB &
KEEP &
SIZE 50000 &
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE
find SUBFILE AND SIZE
Continuation character is &.
then take out SIZE and Next word (Value of 50000 for this case).
note: the word SUBFILE can be SUB, or SUBF or SUBFI ...
also the words can be anywhere in the sentence except SUBFILE.
SUBFILE EMF147.PUB &
SIZE 50000 &
KEEP &
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE
or
SUBFILE EMF147.PUB &
KEEP &
INCL SUBWHSE, DATE-ISSUE &
SIZE 50000 &
INDEX SUBWHSE
...
final result:
SUBFILE EMF147.PUB &
KEEP &
&
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE

2) How can I find the word SUBFILE in the same scenario as above, but this time add the word KEEP if it isn't there in the sentence?
Original string:
SUBFILE EMF147.PUB &
KEEP &
SIZE 50000 &
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE
result: do nothing.
Original:
SUBFILE EMF147.PUB &
SIZE 50000 &
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE
result:
SUBFILE EMF147.PUB KEEP &
SIZE 50000 &
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE

Thanks for the last answer, it worked well.
And hope you can do this, it would same me a lot of time.
Regards,
Charles
Charles

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Re: Merging lines with continuation character and doing repl

Post by Abacre »

pelletic wrote:1) How can I merge lines that have an &, then find if 2 words exists to then replace 3 words?


For this case try the following

Search for:
SUB(.*)SIZE.*&(.*)\Z

Replace with:

SUB$1&$2

I tried it looks like it works.

Sure if needed these r.e. maybe customized to be more precise.

pelletic
Posts: 4
Joined: Mon Jan 31, 2005 5:32 pm

Post by pelletic »

I tried it and it didn't work!
I cut and pasted the statement:
SUBFILE EMF147.PUB &
KEEP &
SIZE 50000 &
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE

in the Regular expression builder,
then used your regular expression and replace by text, and nothing happened...

Maybe you have a different version than I have (version 2.0)
Or maybe it can't be done with your software!

:cry:
Thanks anyway,
At least you tried.
Charles

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre »

Verify that there are not trailing spaced before and after search and replace pairs. I tried first time and it did not work too.
But after that I found out there was a trailing space after \Z

So finally I got resulting code:

SUBFILE EMF147.PUB &
KEEP &
&
INCL SUBWHSE, DATE-ISSUE &
INDEX SUBWHSE


Does it work now?

Post Reply