Replacing space tab with |

Hewlett-packard Hp xw8400 winxp 2.66ghz...
November 3, 2009 at 08:11:27
Specs: Windows XP
Hello again,

I have another misery here how to solve via batch file command. I have this text file that contains with space tab delimiters
i.e.
Apple<space tab>Orange<space tab>Kiwi

results:
Apple | Orange | Kiwi

It should detect all the <space tab> no matter how long the columns will be and replaced by |

Is that possible?

Thanks in advanced!
-Lee-


See More: Replacing space tab with |

Report •


#1
November 4, 2009 at 02:39:51
No idea about <space tab> [sic] but for a TAB, 09hex, delimited try this:

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

@echo off > newfile & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in (my.txt) do (
set S=%%a
set S=!S:	=^|!
>> newfile echo !S!
)


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

M2


Report •

#2
November 4, 2009 at 06:57:21
use a good tool for string parsing. if you can download gawk for windows

c:\test> gawk "BEGIN{OFS=\"|\"}{$1=$1}1" file

GNU win32 packages | Gawk


Report •

#3
November 5, 2009 at 06:25:33
Thanks again Mech but it didn't work on my end withy your sample. I dont have the results when I try to run it. No Error or file 'newfile' created.

Report •

Related Solutions

#4
November 6, 2009 at 04:24:15
Try this line by itself. If you don't get a NEWFILE then I have no clue.

@echo off > newfile & setLocal enableDELAYedexpansion


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

M2


Report •


Ask Question