Computing.Net > Forums > Programming > Replacing space tab with |

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Replacing space tab with |

Reply to Message Icon

Name: leeuy73
Date: November 3, 2009 at 08:11:27 Pacific
OS: Windows XP
Product: Hp (hewlett-packard) Hp xw8400 winxp 2.66ghz 4gb 160gb ws includes 2.66ghz/4mb 1333fs
Subcategory: Batch
Comment:

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-



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 4, 2009 at 02:39:51 Pacific
Reply:

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


0

Response Number 2
Name: ghostdog
Date: November 4, 2009 at 06:57:21 Pacific
Reply:

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


0

Response Number 3
Name: leeuy73
Date: November 5, 2009 at 06:25:33 Pacific
Reply:

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.


0

Response Number 4
Name: Mechanix2Go
Date: November 6, 2009 at 04:24:15 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Replacing space tab with |

Replace BLank Lines With Text www.computing.net/answers/programming/replace-blank-lines-with-text/15368.html

replacing a number with a string www.computing.net/answers/programming/replacing-a-number-with-a-string-/18185.html

Batch tab/space/comma delimited txt www.computing.net/answers/programming/batch-tabspacecomma-delimited-txt/16358.html