Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get a new file without the comments using VBS?? (comments starts with # in each line)

Posted on 2015-02-15
3
Medium Priority
?
54 Views
Last Modified: 2015-02-16
I have a configuration file with a lot of comments (#)
I want to create a new file but without the comments

Example:

Original file:
#this is a test
#this is for apache configuration

RESTART = YES
MODE = ON

New file:
RESTART = YES
MODE = ON
0
Comment
Question by:acunaara
3 Comments
 
LVL 28

Assisted Solution

by:MacroShadow
MacroShadow earned 400 total points
ID: 40610640
Try this:
strFileName = "C:\Temp\OriginalTextFile.txt"

Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.OpenTextFile(strFileName)

Do Until oFile.AtEndOfStream
    If Left(oFile.ReadLine, 1) <> "#" Then
        strTemp = strTemp & oFile.ReadLine & VbCrlf
    End If
Loop

oFile.Close

oFile = "C:Temp\StrippedTextFile.txt"
Set Set oFile = objFSO.CreateTextFile(oFile, True)
objFile.Write strTemp
objFile.Close

Open in new window

0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1600 total points
ID: 40610938
No need for a script for this, just use the FINDSTR command, for example:

findstr /v /r /c:"^[ ]*#" in.txt > out.txt

Open in new window


~bp
0
 

Author Closing Comment

by:acunaara
ID: 40612462
Thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question