Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Blat question:  Does anyone know how to insert carriage return/line feeds in a test string.

Posted on 2010-09-08
Medium Priority
Last Modified: 2012-06-28
I have these variables set in a batch file:

Set BodyLine1="...."
Set BodyLine2="...." etc.
...up to 5.

At some point in the script I issue the command:

Blat -body "%BodyLine1%%BodyLine2%%BodyLine3%...", which works, but strings the text lines together, as expected.  Can I store a CRLF character in a variable and insert it between the lines in the string?  If so, how?

Thank you.
Question by:Randy_R
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2

Expert Comment

ID: 33627998
concatenate the string as follows:
%STring1% + Char(13) + Char(10) + %String2% + ....

Author Comment

ID: 33628136
What I get back is this:

1 + Char(13) + Char(10) + 2 + Char(13) + char(10) + 3 + CHar(13)+Char(10) + 4 + Char(13) + Char(10) + 5

my variables are expanded properly but not the CR/LF.  I tried enclosing the entire string in quotes but it didn't help.
LVL 15

Expert Comment

ID: 33628336
Try embed newlines into the strings like

Set BodyLine1="....\r\n"
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 33628390
Nope.  Just takes them as additional string characters.
LVL 57

Accepted Solution

Bill Prew earned 2000 total points
ID: 33628564
I think what you need to do is write your body lines to a text file first, and then on the blat command line pass in the name of that file, rather than the -body option.  So something like:

echo Sample Line 1>body.txt
echo Sample Line 2>>body.txt
echo Sample Line 3>>body.txt

blat "body.txt" -to ...

LVL 15

Expert Comment

ID: 33628573

Author Comment

ID: 33628746
That did it bp!  Thanks!
LVL 57

Expert Comment

by:Bill Prew
ID: 33628782
Great, glad that was helpful, thanks.

LVL 33

Expert Comment

ID: 38136322
You can use string substitution and a little known trick to achieve this.  For example, let's say you want to use \n to represent your new line characters:

set nltest=This is\na new\nline test.
echo %nltest:\n=&echo.%

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question