Replace Entire Text Blocks
Replace Entire Text Blocks
am 30.09.2007 06:17:33 von awc
Hi Script gurus,
I'm editing a php-based eCommerce site (namely osCommerce, great stuff!)
using Quanta+. The editor has a search utility that allows me to find and
replace text strings across multiple files.
The problem is that I'm trying to find all instances of this text block:
'table_background_cart.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH,
HEADING_IMAGE_HEIGHT); ?> |
....and delete it entirely from a number of files. However, the segment
'table_background_cart.gif' in the middle of the block needs to be replaced
with a wild-card since it changes from page to page. I have not been able
to make regex work in Quanta.
I've tried creating the following script:
#------------------------------------
for file in *.html
do
sed -e 's/\\<\?php echo
tep_image\(DIR_WS_IMAGES \. \' . \', HEADING_TITLE, HEADING_IMAGE_WIDTH,
HEADING_IMAGE_HEIGHT\)\; \?\>\<\/td\>/\ | |
align="right"\>\<\?php echo tep_image\(DIR_WS_IMAGES \. \'\',
HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT\)\; \
\>\<\/td\>/g' $file > temp
mv -f temp $file
done
#------------------------------------
This, of course, does not work:
../replace.sh: line 8: unexpected EOF while looking for matching `''
../replace.sh: line 13: syntax error: unexpected end of file
So, perhaps now it would be good idea to seek help from the elite. Any ideas
will be greatly appreciated.
Thank you,
Alan.
Re: Replace Entire Text Blocks
am 30.09.2007 15:01:42 von Ed Morton
awc wrote:
> Hi Script gurus,
>
> I'm editing a php-based eCommerce site (namely osCommerce, great stuff!)
> using Quanta+. The editor has a search utility that allows me to find and
> replace text strings across multiple files.
>
> The problem is that I'm trying to find all instances of this text block:
>
>
> 'table_background_cart.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH,
> HEADING_IMAGE_HEIGHT); ?> |
>
> ...and delete it entirely from a number of files. However, the segment
> 'table_background_cart.gif' in the middle of the block needs to be replaced
> with a wild-card since it changes from page to page. I have not been able
> to make regex work in Quanta.
>
> I've tried creating the following script:
>
> #------------------------------------
> for file in *.html
>
> do
>
> sed -e 's/\\<\?php echo
> tep_image\(DIR_WS_IMAGES \. \' . \', HEADING_TITLE, HEADING_IMAGE_WIDTH,
> HEADING_IMAGE_HEIGHT\)\; \?\>\<\/td\>/\ | |
> align="right"\>\<\?php echo tep_image\(DIR_WS_IMAGES \. \'\',
> HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT\)\; \
> \>\<\/td\>/g' $file > temp
>
> mv -f temp $file
>
> done
> #------------------------------------
>
> This, of course, does not work:
>
> ./replace.sh: line 8: unexpected EOF while looking for matching `''
> ./replace.sh: line 13: syntax error: unexpected end of file
>
> So, perhaps now it would be good idea to seek help from the elite. Any ideas
> will be greatly appreciated.
>
>
> Thank you,
>
> Alan.
Is that block all on one line or can it be across multiple lines? Can it
occur in the middle of a line? Is the white space always a single blank
char or could it be multiple spaces and/or tabs and/or....?
Ed.
Re: Replace Entire Text Blocks
am 30.09.2007 23:46:00 von awc
Ed Morton wrote:
> awc wrote:
>> Hi Script gurus,
>>
>> I'm editing a php-based eCommerce site (namely osCommerce, great stuff!)
>> using Quanta+. The editor has a search utility that allows me to find and
>> replace text strings across multiple files.
>>
>> The problem is that I'm trying to find all instances of this text block:
>>
>>
>> . 'table_background_cart.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH,
>> HEADING_IMAGE_HEIGHT); ?> |
>>
>> ...and delete it entirely from a number of files. However, the segment
>> 'table_background_cart.gif' in the middle of the block needs to be
>> replaced with a wild-card since it changes from page to page. I have not
>> been able to make regex work in Quanta.
>>
>> I've tried creating the following script:
>>
>> #------------------------------------
>> for file in *.html
>>
>> do
>>
>> sed -e 's/\\<\?php echo
>> tep_image\(DIR_WS_IMAGES \. \' . \', HEADING_TITLE, HEADING_IMAGE_WIDTH,
>> HEADING_IMAGE_HEIGHT\)\; \?\>\<\/td\>/\ | |
>> align="right"\>\<\?php echo tep_image\(DIR_WS_IMAGES \. \'\',
>> HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT\)\; \
>> \>\<\/td\>/g' $file > temp
>>
>> mv -f temp $file
>>
>> done
>> #------------------------------------
>>
>> This, of course, does not work:
>>
>> ./replace.sh: line 8: unexpected EOF while looking for matching `''
>> ./replace.sh: line 13: syntax error: unexpected end of file
>>
>> So, perhaps now it would be good idea to seek help from the elite. Any
>> ideas will be greatly appreciated.
>>
>>
>> Thank you,
>>
>> Alan.
>
> Is that block all on one line or can it be across multiple lines? Can it
> occur in the middle of a line? Is the white space always a single blank
> char or could it be multiple spaces and/or tabs and/or....?
>
> Ed.
Hi Ed. The block is actually a single line with no space at the end. I made
the mistake of simply copying and pasting out of Quanta, which wraps long
lines automatically. If I turn off the Wrap option, the editor displays the
block as one single line (so not a block after all!).
Re: Replace Entire Text Blocks
am 01.10.2007 01:01:00 von Ed Morton
awc wrote:
> Ed Morton wrote:
>
>
>>awc wrote:
>>
>>>Hi Script gurus,
>>>
>>>I'm editing a php-based eCommerce site (namely osCommerce, great stuff!)
>>>using Quanta+. The editor has a search utility that allows me to find and
>>>replace text strings across multiple files.
>>>
>>>The problem is that I'm trying to find all instances of this text block:
>>>
>>>
>>>. 'table_background_cart.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH,
>>>HEADING_IMAGE_HEIGHT); ?> |
>>>
>>>...and delete it entirely from a number of files. However, the segment
>>>'table_background_cart.gif' in the middle of the block needs to be
>>>replaced with a wild-card since it changes from page to page. I have not
>>>been able to make regex work in Quanta.
>>>
>>>I've tried creating the following script:
>>>
>>>#------------------------------------
>>>for file in *.html
>>>
>>>do
>>>
>>>sed -e 's/\\<\?php echo
>>>tep_image\(DIR_WS_IMAGES \. \' . \', HEADING_TITLE, HEADING_IMAGE_WIDTH,
>>>HEADING_IMAGE_HEIGHT\)\; \?\>\<\/td\>/\ | |
>>>align="right"\>\<\?php echo tep_image\(DIR_WS_IMAGES \. \'\',
>>>HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT\)\; \
>>>\>\<\/td\>/g' $file > temp
>>>
>>>mv -f temp $file
>>>
>>>done
>>>#------------------------------------
>>>
>>>This, of course, does not work:
>>>
>>>./replace.sh: line 8: unexpected EOF while looking for matching `''
>>>./replace.sh: line 13: syntax error: unexpected end of file
>>>
>>>So, perhaps now it would be good idea to seek help from the elite. Any
>>>ideas will be greatly appreciated.
>>>
>>>
>>>Thank you,
>>>
>>>Alan.
>>
>>Is that block all on one line or can it be across multiple lines? Can it
>>occur in the middle of a line? Is the white space always a single blank
>>char or could it be multiple spaces and/or tabs and/or....?
>>
>>Ed.
>
>
> Hi Ed. The block is actually a single line with no space at the end. I made
> the mistake of simply copying and pasting out of Quanta, which wraps long
> lines automatically. If I turn off the Wrap option, the editor displays the
> block as one single line (so not a block after all!).
>
You didn't answer the white space question, but if I assume it's a
single blank character, try this:
sed 's:^
tep_image(DIR_WS_IMAGES \. \'.*\', HEADING_TITLE, HEADING_IMAGE_WIDTH,
HEADING_IMAGE_HEIGHT); ?> | $::' file > tmp &&
mv tmp file
Regards,
Ed.