Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch TAB delimit also deletes characters T, A and B upon ECHO

I have about 300 files I need to parse which are tab delimited. The code I'm using below (not finished) is:

for /r C:\mywork2\MAX\ %%f in (*) do (
    for /f "delims=TAB" %%i in (%%f) do (
        for %%u in (%%i) do (
            ECHO %%u
        )
    )
    pause
)

It appears to work fine, except whenever a field begins with a T, A or B the ECHO removes this character? i.e., Taxidea_taxus becomes axidea_taxus. Is this a bug, or can I work around it? I should note that using <TAB> produces the same effect.

like image 520
user3834916 Avatar asked Dec 06 '25 08:12

user3834916


1 Answers

When you specify delims=TAB, the processor uses, literally T, A, and B as delimiters. To use a Tab character, you have enter a literal tab (which will show as whitespace in the script).

Try this:

REM Set a variable to the <TAB> character.
REM Make sure you editor doesn't replace Tabs with spaces.
REM Enter an actual <tab> in the SET statement below.
SET "TabChar=    "

for /r C:\mywork2\MAX\ %%f in (*) do (
    REM Parse with the tab character.
    for /f "delims=%TabChar%" %%i in (%%f) do (
        for %%u in (%%i) do (
            ECHO %%u
        )
    )
    pause
)
like image 73
Jason Faulkner Avatar answered Dec 07 '25 23:12

Jason Faulkner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!