Jump to content

Help with Seeminly Simple RegEx Replacement in Text File


Recommended Posts

I basically have a log file in which I want certain text stripped out. Really simple...or so I thought.

Text I want gone: You do not need to defragment this volume.

Here's the RegEx pattern (which works in the RegexBuddy application):

^(You do not need to defragment this volume.).*$\r\n

I have other more complex ones (the the needs for Regular Expressions, but if I can get this going, I'll be able to do the rest.

I've searched the forums, but can't seem to find exactly what I need. Any help would be appreciated!

Sample........

Master File Table (MFT) fragmentation

Total MFT size = 102 MB

MFT record count = 78,670

Percent MFT in use = 75

Total MFT fragments = 2

You do not need to defragment this volume. <---I would like this line gone

Disk Defrag Analysis - AFTER:

Windows Disk Defragmenter

Link to comment
Share on other sites

I basically have a log file in which I want certain text stripped out. Really simple...or so I thought.

Text I want gone: You do not need to defragment this volume.

Here's the RegEx pattern (which works in the RegexBuddy application):

^(You do not need to defragment this volume.).*$\r\n

I have other more complex ones (the the needs for Regular Expressions, but if I can get this going, I'll be able to do the rest.

I've searched the forums, but can't seem to find exactly what I need. Any help would be appreciated!

Sample........

Master File Table (MFT) fragmentation

Total MFT size = 102 MB

MFT record count = 78,670

Percent MFT in use = 75

Total MFT fragments = 2

You do not need to defragment this volume. <---I would like this line gone

Disk Defrag Analysis - AFTER:

Windows Disk Defragmenter

This script may need altering. It depends on what the vertical whitespace character/s actually is/are at the end of each line.

;
 $sString = "Master File Table (MFT) fragmentation" & @CRLF & _
        "Total MFT size = 102 MB" & @CRLF & _
        "MFT record count = 78,670" & @CRLF & _
        "Percent MFT in use = 75" & @CRLF & _
        "Total MFT fragments = 2" & @CRLF & @CRLF & _
        "You do not need to defragment this volume." & @CRLF & @CRLF & _
        "Disk Defrag Analysis - AFTER:" & @CRLF & _
        "Windows Disk Defragmenter"
 
 MsgBox(0, "RegExpReplace", StringRegExpReplace($sString, "(\v{1,2}You do not need to defragment this volume\.\v{1,4})", ""))
;OR
 MsgBox(0, "StringReplace", StringReplace($sString, @CRLF & "You do not need to defragment this volume." & @CRLF & @CRLF, ""))
;
Link to comment
Share on other sites

Thanks Malkey. I'm actually looking at doing this to a simple text file (e.g. c:\temp\logfile.txt) using RegEx funtions, so that's where my brain freeze is happening (manipulating a file). Anything you could offer would be appreciated!

Link to comment
Share on other sites

Thanks Malkey. I'm actually looking at doing this to a simple text file (e.g. c:\temp\logfile.txt) using RegEx funtions, so that's where my brain freeze is happening (manipulating a file). Anything you could offer would be appreciated!

You can use FileReadLine() in a While loop until you hit the line you want. Keep a counter so that you know what line you are at. Then once you find that line, use _FileWriteToLine() and the counter to rewrite the line you need.

Just an idea, hope it helps.

[font="Times New Roman"]Ocho.[/font]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...