Page 1 of 1

Reading tab and new line characters

Posted: 03 Feb 2014 02:48
by stephjo
Hi folks,

I am working on a simple script that can read a file and display contents line-by-line. The following script (from another thread here) doesn't display the new line and tab characters in the read file. My hunch is that the solution is rather simple, but I can't seem to figure it out. Could you please help?

Thanks!
-Steph

test.bat is here:

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('type filename.txt') do (
set line=%%a
echo !line!
PAUSE>NUL|SET /P=
)


filename.txt is here:

Code: Select all

header1
   sam
   bob
   stephen

header2
   sam
   bob
   stephen

Re: Reading tab and new line characters

Posted: 03 Feb 2014 06:06
by foxidrive
Replace "tokens=*" with "delims=" as the former strips leading whitespace.

Re: Reading tab and new line characters

Posted: 03 Feb 2014 08:41
by stephjo
Foxidrive: Thank you. The "tokens=*" to "delims=" displays tabs. How about empty lines (consecutive new line characters?)

Re: Reading tab and new line characters

Posted: 03 Feb 2014 10:57
by Sponge Belly
Hi Steph! :-)

Read the recent slice.cmd topic. It should answer your questions. And if you’re still having difficulties after that, don’t hesitate to get in touch.

- SB

Re: Reading tab and new line characters

Posted: 03 Feb 2014 17:16
by foxidrive
A for /f command strips blank lines.

There are ways to include blank lines, by numbering the lines and then getting rid of the numbers by parsing them out.

If you discuss what you intend to do, with some example data, then someone may give you more robust ways of doing it.