selective replacing text using sed/perl

Hi,

I have the following text which I want to search and replace using perl and sed. I would appreciate any help.
Please notice the file contains schema name with a single dot and a double dot . &&WEBDIR_SCHEMA. and &&WEBDIR_SCHEMA .. }

I would like to change it to the acutal schema name.tablename
The schema name in this case will be DSP

Before

SELECT COUNT(*) INTO CTR FROM &&WEBDIR_SCHEMA.SYSPROP WHERE DOMAIN = 'test' AND PNAME = 'svcURL';

SELECT COUNT(*) INTO CTR FROM &&WEBDIR_SCHEMA..SYSPROP
WHERE DOMAIN = 'test' AND PNAME = 'MaxConnectionsHost';

After
SELECT COUNT(*) INTO CTR FROM DSP.SYSPROP WHERE DOMAIN = 'test' AND PNAME = 'svcURL';

SELECT COUNT(*) INTO CTR FROM DSP.SYSPROP
WHERE DOMAIN = 'test' AND PNAME = 'MaxConnectionsHost';

Thanks,

In sed.,

sed 's/&&WEBDIR_SCHEMA\.\{1,2\}/DSP./' FILENAME

In Perl.,

perl -e 'while(<>){ s/&&WEBDIR_SCHEMA\.{1,2}/DSP./;print }' FILENAME

How can do in the following way ?

#!/bin/bash
USER=DSP
for line in `ls test_001.sql`
do
perl -pi -e 's/&&WEBDIR_SCHEMA\.{1,2}/${USER}./g' ${line}
done

---------- Post updated at 10:27 AM ---------- Previous update was at 07:39 AM ----------

Thank-you Geek, I figured out a way to use your suggestion and modify it necessary to my needs.
Thanks for jumpstarting me ! I really appreciate.

I am very eager to know,

  1. What is the solution you found ( you wanted ) ?
  2. What modifications.. and the path in learning ( what ever possible to explain ).

To keep the forums high quality for all users, please take the time to format your posts correctly.

  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags and by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

@jville please edit your posts and add code tags.

Thanks,

done ! thanks.

---------- Post updated at 06:45 AM ---------- Previous update was at 06:34 AM ----------

Geek ,
Please notice the single quotes in the sed commad for ${USER}

I took the liberty to change the perl command you had provided.

perl -e 'while(<>){ s/&&WEBDIR_SCHEMA\.{1,2}/DSP./;print }' FILENAME
#!/bin/bash
USER=DSP
for line in `ls test_001.sql`
do
perl -pi -e 's/&&WEBDIR_SCHEMA\.{1,2}/'${USER}.'/g' ${line}
done