Solved

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

Posted on 2015-02-15
3
50 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 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 53

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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