|
Home > Archive > Unix Shell > September 2007 > Replace Entire Text Blocks
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Replace Entire Text Blocks
|
|
|
| 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:
<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES .
'table_background_cart.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH,
HEADING_IMAGE_HEIGHT); ?></td>
....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/\<td class="pageHeading" align="right"\>\<\?php echo
tep_image\(DIR_WS_IMAGES \. \' . \', HEADING_TITLE, HEADING_IMAGE_WIDTH,
HEADING_IMAGE_HEIGHT\)\; \?\>\<\/td\>/\<td class="pageHeading"
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.
| |
| Ed Morton 2007-09-30, 1:24 pm |
| 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:
>
> <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES .
> 'table_background_cart.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH,
> HEADING_IMAGE_HEIGHT); ?></td>
>
> ...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/\<td class="pageHeading" align="right"\>\<\?php echo
> tep_image\(DIR_WS_IMAGES \. ' . ', HEADING_TITLE, HEADING_IMAGE_WIDTH,
> HEADING_IMAGE_HEIGHT\)\; \?\>\<\/td\>/\<td class="pageHeading"
> 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.
| |
|
| Ed Morton wrote:
> awc wrote:
>
> 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!).
| |
| Ed Morton 2007-09-30, 7:18 pm |
| awc wrote:
> Ed Morton wrote:
>
>
>
>
> 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:^<td class="pageHeading" align="right"><?php echo
tep_image(DIR_WS_IMAGES \. '.*', HEADING_TITLE, HEADING_IMAGE_WIDTH,
HEADING_IMAGE_HEIGHT); ?></td>$::' file > tmp &&
mv tmp file
Regards,
Ed.
|
|
|
|
|