Solved

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

Posted on 2015-02-15
3
48 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 26

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 51

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now