We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

echoimg multiple lines of text

chetan1981
chetan1981 asked
on
Medium Priority
270 Views
Last Modified: 2012-05-07
Hi,

I am trying to echo multiple lines into a text fil but it fails everytime it hits a ". Is there anyway to use escape characters with echo,

Here's the code I am trying to echo

SET SMTPSERVER=smtp.xxxx.com
SET MAILPATH=D:\
REM SET MAILUSER=
SET MAILFROM=SQL %COMPUTERNAME%
SET MAILTO=SQLTEAM
rem check if datalist variable exists.
if "%DATALIST%"=="" (
SET MAILSUBJ=SQL Data protector %SERVERNAME% Backup **FAILED**
SET MAILBODY=Backup of %SERVERNAME% started at %STARTTIME% failed:  No Datalist Variable
goto :SendMail
)
rem echo before parse %datalist% > %LOGSERVERNAME%
Comment
Watch Question

Britt ThompsonSr. Systems Engineer
Top Expert 2009

Commented:
the echo escape character is "^"
Britt ThompsonSr. Systems Engineer
Top Expert 2009

Commented:
You can always copy that to a text file and use "type filename.txt" to display all the lines or echo them to another file.

Author

Commented:
Thanks!!

One more thing..the command prompt appears before every new line..

C:\>SET SMTPSERVER=smtp.xxxx.com
C:\>SET MAILPATH=D:\
C:\>REM SET MAILUSER=


Any way that I can avoid that.

Thanks again


Britt ThompsonSr. Systems Engineer
Top Expert 2009

Commented:
In which case is the command prompt appearing? What's the exact code you're using?

Author

Commented:
echo "SET SMTPSERVER=smtp.xxxx.com
SET MAILPATH=D:\
REM SET MAILUSER=
SET MAILFROM=SQL %COMPUTERNAME%
if ^"%DATALIST%"==^"^" (
" > file.txt


This is what I tried
Thanks

Author

Commented:
I can not copy from a file into a new file as the file does not currently exist on the server and I can just have one file at a time on the server
Britt ThompsonSr. Systems Engineer
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
You just need to add @echo off at the start for the c:\ bit...
Britt ThompsonSr. Systems Engineer
Top Expert 2009

Commented:
That does get rid of the c:\ but it still doesn't allow the echo'ed lines to be inserted into the text file...I'm interested if you know how to do that? Would make my life easier.
Top Expert 2009

Commented:
Can you provide the example of what you want the text file to look like?
Top Expert 2009

Commented:
OK. I'll just take what you have in your question literally.

I set the LOGSERVERNAME so I can test it.
@ECHO OFF
Set LOGSERVERNAME=C:\Output.cmd
(
ECHO SET SMTPSERVER=smtp.xxxx.com
ECHO SET MAILPATH=D:\
ECHO REM SET MAILUSER=
ECHO SET MAILFROM=SQL %%COMPUTERNAME%%
ECHO SET MAILTO=SQLTEAM 
ECHO rem check if datalist variable exists.
ECHO if "%%DATALIST%%"=="" ^(
ECHO SET MAILSUBJ=SQL Data protector %%SERVERNAME%% Backup **FAILED**
ECHO SET MAILBODY=Backup of %%SERVERNAME%% started at %%STARTTIME%% failed:  No Datalist Variable
ECHO goto :SendMail
ECHO ^)
ECHO rem echo before parse %%datalist%%
) > %LOGSERVERNAME%

Open in new window

Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Britt ThompsonSr. Systems Engineer
Top Expert 2009

Commented:
Much better for me...thanks. I didn't know you could wrap it in parenthesis like that. Nice solution...still not a pretty as a SHELL script echo but better than what I've been doing for sure.

Much obliged.

Author

Commented:
Thanks to both of u...works perfectly.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.