delim to first tab

January 29, 2010 at 05:11:51
Specs: Windows XP, 3mhz/2 gig
Hi all. I need to get all characters into a variable up to the first TAB. My file is as follows:
document1.bat'TAB''TAB'1
doc2.bat'TAB''TAB''TAB'5
mydocument3.bat'TAB'2
etc.
I used 'TAB' to represent a TAB in my file.

all i want is the documentname.bat in a variable. I have this so far:

for /f "tokens=* delims= " %%a in ('find "." ^< HistoryLog.log') do (
set sendline=%%a
::I need to set the variable here.
)


See More: delim to first tab

Report •

#1
January 29, 2010 at 05:29:52
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=

for /f "tokens=1" %%a in (myfile) do (
set /a N+=1
set v!N!=%%a
)

set v


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

M2


Report •

#2
January 29, 2010 at 05:53:46
Thanks M2, so for the future can I assume that "tokens=2"
wouls skip to the second tab?

Report •

#3
January 29, 2010 at 18:20:01
Not the second TAB; the second token.


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

M2


Report •

Related Solutions

#4
February 1, 2010 at 08:22:44
Actually the separator is both whitespace and TAB, so it would be the second string, where the active separators are either whitespace or TAB

So ... be careful with whitespaces

TAB's are a pain in the ass, try to get rid of them. They are hard to handle, and their purpose is obsoleted.


Report •

#5
February 1, 2010 at 09:34:17
Yeah, tabs are a pain. And useless.


But you can get the token even if it has a space.

try this bat:

=================================


@echo off > newfile & setLocal enableDELAYedeXpansion

set N=

for /f "tokens=2 delims=	" %%a in (myfile) do (
set /a N+=1
set v!N!=%%a
)

set v

=================================
on this file:
===========================
one	two	three
four	fi ve	six

===========================
HINT: the default is whitespace. [tab & sp] This tells it to ignore sp.


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

M2


Report •

#6
February 1, 2010 at 09:56:41
"TAB's are a pain in the ass, try to get rid of them. They are hard to handle, and their purpose is obsoleted."

That can be true at times, but sometimes tabs are useful as a delimiter if you need all ascii 32 - 126(decimal) for the data fields in a ascii based list(ie .tsv).

Edit:
Err maybe that's be 33 - 127, I hate switching back and forth between zero and one based offsets......
Err, Maybe not.


Batch Variable how to


Report •

#7
February 2, 2010 at 00:50:08
Well thank you guys, thats exactly what I needed. I am now using two FOR loops, one with "tokens=1" and the other with "tokens=2". I never understood TOKENS before.. Now I can move on to delims and I am sure that will come easily.
Cheers, have a good Tuesday!

Report •

#8
February 2, 2010 at 01:37:49
Hi lee,

I'm glad the fog is beginning to lift.

delims has it's own quirks.


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

M2


Report •

#9
February 3, 2010 at 08:32:33
Indeedy ... didn't know that TABs are part of default separator list in the FOR /F list ... well, there you go.

M2 : its own quirks ... also in languages, single quotes are important ;)


Report •

#10
February 3, 2010 at 09:22:10
I have no idea what that means.


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

M2


Report •

Ask Question