Computing.Net > Forums > Programming > VBScript help parsing a text 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 help parsing a text file

Reply to Message Icon

Name: humerick
Date: May 15, 2006 at 10:34:05 Pacific
OS: WinXP
CPU/Ram: Pentium
Product: Dell
Comment:

We are switching over from our Unix version of software to a windows version. I only know korn shell scripting, and now need to learn VBScript. Can someone help me get started with rewriting a shell script in VBScript? What I need to do is loop through a directory looking for all files that begin with FPACTAPE.C*. I need to check and see if the first char of the first line is a "1", and the first character of the second line is a "9". If they meet that criteria, then I skip the file. Otherwise I need to concatenate each file into a file called CAAPACTP.DAT. Any help with getting me started on this will be greatly appreciated.

Thanks,
Scott




Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: May 15, 2006 at 14:56:50 Pacific
Reply:

It would probably be easier for me to write it for you than to walk you though it, but then you wouldn't learn anything!

Start by reading through this page: http://www.windowsdevcenter.com/pub/a/oreilly/windows/news/vbscriptpr_0201.html

There is an example towards the bottom (source code provided) which searches through an entire drive for batch files. The program has a function that recursively calls itself in order to go into sub directories. If you are only needing to look in one directory (and not subdirectories) you will not need to do that.

but the example should be enough for you to accomplish the first part of your problem of looping through files in a directory and finding the ones that begin with "FPACTAPE.C*"

So start with that and post back if you have problem or question. Once that is done we can move on to reading the contents of the files.

Michael J


0

Response Number 2
Name: Mechanix2Go
Date: May 16, 2006 at 08:21:25 Pacific
Reply:

Hi Scott,

I don't envy you having to give up ksh and learn something else; but there we are.

Like Michael J., it's easier to do it than teach it.

VBS and perl both have more horsepower than BATCH scripts.

For now, to get you going, you can try the BAT below. You will need to modify the drive/directory/filespec in () in the first 'for' line to suit your files to check.

:: == cat-19.bat
:: concat all matching files UNLESS:
:: 1st char of 1st line is 1 AND
:: 1st char of 2nd line is 9

@echo off > CAAPACTP.DAT

:main
setlocal
for /f "tokens=* delims=" %%F in ('dir /b/s/a-d c:\temp\??.bat') do (
call :sub1 %%F)
endlocal
goto :eof

:sub1
set currFILE=%*
set lineNUM=0
for /f %%L in (%1) do call :sub2 %%L
if %first%%second% neq 19 type %currFILE% >> CAAPACTP.DAT
goto :eof

:sub2
set currLINE=%*
set /a lineNUM+=1
if %lineNUM% gtr 2 goto :eof
if %lineNUM% equ 1 set first=%currLINE:~0,1%
if %lineNUM% equ 2 set second=%currLINE:~0,1%
goto :eof
:: DONE



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 3
Name: humerick
Date: May 17, 2006 at 13:12:31 Pacific
Reply:

Thanks Michael J and M2. I hope to look into your solutions tomorrow. I've been working on some other issues here at work. I'll get back to you if I have any questions.
Thanks again,
Scott


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBScript help parsing a text file

Help browsing a text file www.computing.net/answers/programming/help-browsing-a-text-file/9929.html

VBScript help creating a log file www.computing.net/answers/programming/vbscript-help-creating-a-log-file-/14414.html

vbscript to parse text file and com www.computing.net/answers/programming/vbscript-to-parse-text-file-and-com/16691.html