vbscript to read pipe delimited file

Microsoft Windows xp professional editio...
September 11, 2009 at 04:12:57
Specs: Windows XP
Hi
I have a requirement wherein i have a pipe delimited text file with multiple records.
Requirement is to read each record from the file and create a corresponding record in a new file.
The record in the new file will have different fields..some fields need to be copied from the input file and some have to be defaulted.
In the new file, the fields which are not required will be replaced by a pipe.
In short, for every record in input file, corresponding record has to be created in new file.
Any help on this will be greatly appreciated

See More: vbscript to read pipe delimited file

Report •


#1
September 11, 2009 at 06:28:52
I dunno vbs but it can probably be done in batch. You need to be specific about what to leave in and what to leave out. [As the song says.]


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

M2


Report •

#2
September 11, 2009 at 06:54:26
Mechanix2Go: I dunno vbs but it can probably be done in batch.
In this instance, I'd prefer VBS to batch, seeing as the delimiter is a CMD special character and all.

I'd do an example, but I'm waiting for Programmer to clarify "some."


Report •

#3
September 11, 2009 at 07:24:25
hi
for example, from the input file, i want to copy the first 4 fields as it is to the new file.
fifth field in the new file will be a combination of field 5 and field 6 from input file separated by -.
6th field in new file has to be defaulted to current date..
hope this clarifies

Report •

Related Solutions

#4
September 11, 2009 at 07:43:33
Hi R2,

Yeah, I know it's micky-mouse.

=================================
@echo off > newfile & setLocal EnableDELAYedExpansion
@echo off > new.psv

for /f "tokens=1-9 delims=|" %%a in (my.psv) do (
echo %%a,%%b,%%c,%%d,%%e-%%f,%date% >> newfile
)

for /f "tokens=* delims= " %%a in (newfile) do (
set str=%%a
set str=!str:,=^|!
echo !str! >> new.psv
)


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

M2


Report •

#5
September 11, 2009 at 07:59:05
Const inName = "input.psv"
Const out    = "out.psv"
Dim outLine(5)
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.OpenTextFile(out, 2, True)

With fso.OpenTextFile(inName, 1)
  Do Until .AtEndOfStream
    inLine = Split(.ReadLine, "|")
    For i = 0 To 3
      outline(i) = inLine(i)
    Next
    outLine(4) = inLine(4) & "-" & inLine(5)
    outLine(5) = Date()
    outFile.WriteLine Join(outLine, "|")
  Loop
End With


Report •

#6
September 13, 2009 at 23:55:34
Thnx Mechanix..this works great...

Report •


Ask Question