Replacing a sentence with a multiline text.

Replacing a sentence with a multiline text.

Post by arunrajmo.. » Fri, 01 Apr 2005 19:58:23



Hello,

I have couple of shell scripts that contain the following line

db2 connect to ${DBNAME}

I need to replace this line with a block of code ( this code is in
another file )

I know I need to do it with sed. But the sed interprets the ${DBNAME}
as an environ variable and looks out for substitution)

Help out!

Thanks.
Arun

 
 
 

Replacing a sentence with a multiline text.

Post by arunrajmo.. » Fri, 01 Apr 2005 20:42:48


This is the block of code inside the other file

sqlplus -s <<EOF 2>&1 > $<filename>.txt

$uid/$pwd

SET SERVEROUTPUT ON

SET HEAD OFF

SET FEEDBACK OFF

WHENEVER SQLERROR EXIT.SQLCODE

BEGIN

   DBMS_OUTPUT.ENABLE(30000)

   COMMIT;

EXCEPTION

  WHEN OTHERS THEN

    DBMS_OUTPUT.PUT_LINE('Change the error message');

    DBMS_OUTPUT.PUT_LINE(SQLCODE||'-'||SQLERRM);

    ROLLBACK;

    RAISE;

END;

/

EXIT;

EOF

plsqlerror=$?

if [ $plsqlerror -ne 0 ]

then

   echo "change the error message"

   TITLE="${HOST}==>ABEND==> Change the error message "

   print "${ENVR}==>${PROG_NAME}==> Change the error message " >>
${LOG_FILE}

   print "ABEND ==>${TITLE}" >> ${LOG_FILE}

   Mail -s "${TITLE}" ${<Give appropriate mailing list>} < ${LOG_FILE}

   Mail -s "${TITLE}" ${<Give appropriate mailing list>} < ${LOG_FILE}

   exit 1

fi

 
 
 

Replacing a sentence with a multiline text.

Post by Alan Conno » Sat, 02 Apr 2005 03:30:36


On comp.unix.shell, in


> Hello,

> I have couple of shell scripts that contain the following line

> db2 connect to ${DBNAME}

> I need to replace this line with a block of code ( this code is
> in another file )

> I know I need to do it with sed. But the sed interprets
> the ${DBNAME} as an environ variable and looks out for
> substitution)

> Help out!

> Thanks.  Arun

Give this a try Arun:

sed -e '/^db2 connect to ${DBNAME}/r file-with-code' \
-e '/^db2 connect to ${DBNAME}/d' inputfile > outputfile

mv outputfile inputfile

If you have a sedscript in a bash script, and you have to use "
instead of ' because there's a variable in the sedscript that you
want sed to read the contents of, you need to escape any $ that
are not referring to the variable like so \$.

sed "\$s/.*/{var}/" ...

Meaning: Go to the last line and switch it for the contents
of $var.

AC

 
 
 

Replacing a sentence with a multiline text.

Post by arunrajmo.. » Thu, 07 Apr 2005 22:06:31


THANKS!!!
 
 
 

1. sed: multiline replace skips

I'm inserting a character to every link that does not precede a header tag:

/A>$/{
N
s/A>\n<li><A/A> \&#149; \
<li><A/

But the insertion of " &#149; " alternates lines, only adding to every other
line. How to make it operate on every line?

Sample:

<li><A HREF="http://127.0.0.1/">Localhost</A> &#149;
<li><A HREF="http://127.0.0.1/">Localhost</A>
<li><A HREF="http://127.0.0.1/">Localhost</A> &#149;
<li><A HREF="http://127.0.0.1/">Localhost</A>
<li><H3>Daily</H3>

-- Gnarlie
http://www.Spectrumology.com
Spectrumology is the science of chaos.

2. any patches to get SVGATextMode working with the Millenium II yet?

3. Korn Shell: Using sed to replace string with multiline string?

4. ATI Mach 64 only VGA16? Help!

5. Q: multiline sed search/replace

6. Can't compile slhc; make ignores -I../../net/inet

7. How can i replace Logon and Password Text (not welcome text) in CDE Banner ?

8. searching authentication methods ?

9. Search and replace text in a bunch of text files..

10. Sed: Replace text in one file with SPECIFIC text from another

11. Search and replace text in a bunch of text files

12. lpadmin -D multiline text

13. Need HELP with text replace from cmd line