how to inculde a new line charcter while read

December 30, 2009 at 03:17:01
Specs: Windows XP
Hello,

I'm using the following code for reading the content of the file to variable. we have one problem where in the Separator should be a new line character and unable to get that.


@echo off
setlocal enabledelayedexpansion
SET _filepath=%1
:: below code is used for removing the double codes in the filename that is passed.

SET _filepath=###%_filepath%###
SET _filepath=%_filepath:"###=%
SET _filepath=%_filepath:###"=%
SET _filepath=%_filepath:###=%

echo String : %_filepath%

set SEPARATOR=
set filecontent=
for /f "delims=" %%a in (%_filepath%) do ( set currentline=%%a set filecontent=!filecontent!%SEPARATOR%!currentline!
)

echo The file contents are: %filecontent%

Can any one please help on this.

Vinayaka


See More: how to inculde a new line charcter while read

Report •


#1
December 30, 2009 at 06:06:32
It's not often I look at a piece of code and have no idea what's going on.


"the double codes in the filename"

If I knew what that meant I might figure out the next 4 SETs.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
December 30, 2009 at 06:25:18
Hello,

Thanks for the reply.

SET _filepath=###%_filepath%###
SET _filepath=%_filepath:"###=%
SET _filepath=%_filepath:###"=%
SET _filepath=%_filepath:###=%

above lines are for removing the double codes

for example

if i pass the argument has "E:\Test\Test.txt" it will be converted into E:\Test\Test.txt

my concern is in this part

set SEPARATOR=
set filecontent=
for /f "delims=" %%a in (%_filepath%) do ( set currentline=%%a set filecontent=!filecontent!%SEPARATOR%!currentline!
)

echo The file contents are: %filecontent%

I'm getting contents of file in single line.

How can i include a new line character for variable "SEPARATOR". so that output will be in different line.

Vinayaka



Report •

#3
December 30, 2009 at 08:54:52
About removing the double quotes

for %%j in (%_filepath%) do set _filepath=%%~j

but there is no way to insert a LF or CR as separator into a variable.

Report •

Related Solutions

#4
December 30, 2009 at 11:28:49
i got one into the environment table by accident once, but i didn't check up on it (ie, which batchfile messed up and how).
when i typed SET, it looked like:
VARTEST
variable_content

Report •

#5
December 30, 2009 at 12:19:22
I don't know where you're going with this. If you put in:

E:\Test\Test.txt

then what?


=====================================
Helping others achieve escape felicity

M2


Report •

#6
January 1, 2010 at 04:39:26
I guess he wants to parse the newline character ...
If that is the case, I would propose to go and find another separator, since this character is extremely hard to work with, it't not really a character anyway.

Report •

Ask Question