Reading tab and new line characters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stephjo
Posts: 12
Joined: 03 Feb 2014 02:39

Reading tab and new line characters

#1 Post by stephjo » 03 Feb 2014 02:48

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Reading tab and new line characters

#2 Post by foxidrive » 03 Feb 2014 06:06

Replace "tokens=*" with "delims=" as the former strips leading whitespace.

stephjo
Posts: 12
Joined: 03 Feb 2014 02:39

Re: Reading tab and new line characters

#3 Post by stephjo » 03 Feb 2014 08:41

Foxidrive: Thank you. The "tokens=*" to "delims=" displays tabs. How about empty lines (consecutive new line characters?)

Sponge Belly
Posts: 231
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Reading tab and new line characters

#4 Post by Sponge Belly » 03 Feb 2014 10:57

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Reading tab and new line characters

#5 Post by foxidrive » 03 Feb 2014 17:16

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.

Post Reply