Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 felicityM2

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

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

Hi R2,
Yeah, I know it's micky-mouse.
=================================
@echo off > newfile & setLocal EnableDELAYedExpansion
@echo off > new.psvfor /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 felicityM2

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

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |