Convert Caret (^) delimited textfile to Pipe

March 10, 2010 at 19:35:41
Specs: Windows server 2008
Hi,
I would like to convert Caret (^) delimited files to Pipe delimited files in a folder.

So the script should convert inFile to Outfile as below.

inFile

1^2^3^4
3^5^7^8
4^7^8^9

outfile

1|2|3|4
3|5|7|8
4|7|8|9



See More: Convert Caret (^) delimited textfile to Pipe

Report •

#1
March 10, 2010 at 20:05:24
This is mickey-mouse but it's a start.

------------------------------
@echo off > outfile & setLocal enableDELAYedeXpansion

for /f "tokens=1-7 delims=^" %%a in (infile) do (
set S=%%a %%b %%c %%d
set S=!S: =^|!
>> outfile echo !S!
)


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

M2


Report •

#2
May 3, 2010 at 16:07:04
could something like this be used on a fixed length file? such as field1 is 1-10 spaces, then field2 is 11-24 being switched to field1|field2 ?

Report •

#3
May 3, 2010 at 17:00:29
yes,
for /f "tokens=*" %%a in (file) do (
set x=%%a
set out=!x:~0,10!^|!x:~10,10!
>> newfil echo !x!

Report •
Related Solutions


Ask Question