Solved

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

Posted on 2015-02-15
3
52 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Assisted Solution

by:MacroShadow
MacroShadow earned 100 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 56

Accepted Solution

by:
Bill Prew earned 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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