Solved Seting Parameters using tab delimited text file/batch

July 29, 2013 at 12:48:14
Specs: Windows 7
I am trying to set a parameter using tab delimited text files. I have never done this so as far as troubleshooting it, I am stuck. The code I came up with doesn't return anyting, and I can't find any hints or examples as to how to do this anywhere I search. My code is as follows

for /f "tokens=6 delims=" %%i in (%Server%%ParamS:~0,3%\%ParamS:~0,5%\%ParamS%\Support\%Param%.txt) do (
set ParamD=%%i
Echo. %ParamD%

The line of text I am trying to use for ParamD will always be on the first row, directly after the 6th tab.

I don't know what I'm doing wrong, can someone please help?

See More: Seting Parameters using tab delimited text file/batch

Report •

July 29, 2013 at 20:43:11
✔ Best Answer
The "delims=" is killing it. Run without that clause:
for /f "tokens=6" %%i in (%Server%%ParamS:~0,3%\%ParamS:~0,5%\%ParamS%\Support\%Param%.txt) do (
set ParamD=%%i
This will default to delims as tabs and spaces. ("delims=" means no delimiters in effect). Note that spaces in the data might still kill you since those and tabs are counted equally. If that happens, you need to specify the TAB only. A sample of the data-file would help to resolve.
ps: I recommend always run tests with cascading complexity. Run initial tests with bare minimum (both code AND data),, then work up from there, and use LOTS of echos and pauses to examine variable values and code-location.

message edited by nbrane

Report •

July 30, 2013 at 05:34:13
This works! However like you said it is counting tabs and spaces, so I had to change the number to 11, and it didn't pull the whole line of text because it just used the text after 11 until the first space. Its good to finally see progress! Thank you for the quick response!
Now As I said this is my first try with pulling information from a text file, so I have no clue, how do I tell it to count tabs instead of spaces?
Again, thank you for your response once I get this figured out this is going to greatly reduce my time on this task!

Report •

July 30, 2013 at 05:35:18
Example of first line of one of the text files:

Index No. Qty U/M Part No. Component Description Section 31916017 STATIONARY SHEARLOCK ASSY(X115
1 1.00 EA

Report •

Related Solutions

July 30, 2013 at 06:15:40
I think I got it through trial and error, it seems to do what I want it to . . . . .

This is what I got:

for /f "tokens=8 delims= " %%i in (%Server%%ParamS:~0,3%\%ParamS:~0,5%\%ParamS%\Support\%Param%.txt) do (
set ParamD=%%i

You can't really tell on here, you probably already know though, that after 8 delims=[TAB]'

message edited by Shannon82

Report •

July 30, 2013 at 07:29:53
{Update: Modified Question}
Ok the code I proved earlier works except one thing, it is pulling text from the next tab also. I have researched it, and found out that in most of my .txt files the end of tab 8 runs almost right up against the beginning of tab 9 (sorry if I am not using proper terminology)
So in the example I proveded the return I get for %ParamD%should be:


Instead it is returning


Notice the addition of 1 at the end.

Is there anyway to tell it to only use text after the 8th tab and before the 9th tab?

Report •

July 30, 2013 at 18:23:28
What you have coded should do the job. It should only be picking up the content of the eighth tab into var. %%i, unless the true file delimiter between field 8 and 9 is not in fact a TAB. I would first examine the files that fail to make sure that it's not a space. If you want, post another copy of those files that fail, with something to represent tabs, like "~". Then I can run tests. Like you said, I can't see TABs on here.
EDIT /70 will show tabs versus spaces. I'll pmail my email if you still have problems, and you can forward a copy of the "bad" files.

Report •

July 31, 2013 at 01:38:42
I can't tell from #3 whether the line breaks at X115 or whether the forum broke it

I'm goping to paste in a long line with tags. Look at the page source. [CTRL-U in Firefox]

The line below is 106 chars long.  Don't think about TABs in here because my editor takes them out. The point is to show how to post long lines and keep the needed layout. This line goes to 194.
Index No. Qty U/M Part No. Component Description Section 31916017 STATIONARY SHEARLOCK ASSY(X115 1 1.00 EA

M2 Golden-Triangle

Report •

July 31, 2013 at 05:23:29
I didn't think about that, the text files are originally better formatted with returns. Due to the main program I used the text files for, I have to run them through a differant program that deletes the return symbol, essentially putting it all on one line. So as you said, there is no tab between 8 & 9, I guess the solution is simply running my batch file on them before I delete those return keys.

Thank you all for your input on this, despite this little setback I got my work done in less than half the time it usually takes!

Report •

July 31, 2013 at 07:00:13
Post your final script so we can learn from it.

M2 Golden-Triangle

Report •

July 31, 2013 at 07:08:05
for /f "tokens=8 delims=[TAB]" %%i in (%Server%%ParamS:~0,3%\%ParamS:~0,5%\%ParamS%\Support\%Param%.txt) do (
set ParamD=%%i
Echo. %ParamD%

Thats what I ended up with

Report •

Ask Question