Computing.Net > Forums > Windows XP > vbscript to read pipe delimited file

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.

vbscript to read pipe delimited file

Reply to Message Icon

Name: Programmer
Date: September 11, 2009 at 04:12:57 Pacific
OS: Windows XP
Product: Microsoft Windows xp professional edition
Subcategory: General
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: September 11, 2009 at 06:28:52 Pacific
Reply:

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


0

Response Number 2
Name: Razor2.3
Date: September 11, 2009 at 06:54:26 Pacific
Reply:

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."


0

Response Number 3
Name: Programmer
Date: September 11, 2009 at 07:24:25 Pacific
Reply:

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


0

Response Number 4
Name: Mechanix2Go
Date: September 11, 2009 at 07:43:33 Pacific
Reply:

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


1

Response Number 5
Name: Razor2.3
Date: September 11, 2009 at 07:59:05 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: Programmer
Date: September 13, 2009 at 23:55:34 Pacific
Reply:

Thnx Mechanix..this works great...


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: vbscript to read pipe delimited file

Unable to read MS-Excel file www.computing.net/answers/windows-xp/unable-to-read-msexcel-file/35334.html

How to read the shorcut file? www.computing.net/answers/windows-xp/how-to-read-the-shorcut-file/178802.html

Unable to read files from CD-RW www.computing.net/answers/windows-xp/unable-to-read-files-from-cdrw/146698.html