Sign in to follow this  
Followers 0
Angrysteel

Search and Copy Text

5 posts in this topic

I have several log file i would like to pull text from and write to a new text file. I am not sure how to get started on this.

Sample of the Log file:

Backing up c:/med-edi/ME.BP.O/MENU.DRIVER

Backing up c:/med-edi/ME.BP.O/MENU.WINDOW

Backing up c:/med-edi/ME.BP.O/PC

Backing up c:/med-edi/ME.CF

Backing up c:/med-edi/ME.CF/.Type1

Backing up c:/med-edi/ME.CF/01.SND

Backing up c:/med-edi/ME.CF/DSM01.SND

Backing up c:/med-edi/ME.CF/EDISTAT.txt

Backing up c:/med-edi/ME.CF/STO.449200

WARNING: The magic number of this file is byte-swapped, indicating

the file did not originate on this platform.

Saving as SYSTEM type file!

Backing up c:/med-edi/ME.CTL

Backing up c:/med-edi/ME.POPF

Backing up c:/med-edi/ME.TPF

Backing up c:/med-edi/reg

Backing up c:/med-edi/reg/dump.REG.RTF

Backing up c:/med-edi/reg/REG.RTF

Backing up c:/med-edi/TEMP

Backing up c:/med-edi/USER.MPQ

Backing up c:/med-edi/USER.MPQ/.Type1

Backing up c:/med-edi/VOC

Backing up c:/med-edi/VOCLIB

Total files: 241 Total bytes : 8087823 Elapsed Time: 00:00:05

222 operating system files processed, 0 broken, totalling 405313 data bytes.

19 UniVerse files processed, 0 corrupted.

36666 UniVerse records processed, 0 corrupted, totalling 7682510 data bytes.

0 extended keys processed, 0 not supported at specified revision level.

EndOfUvbackup

I want to extract from Total files: ...... EndOfUvbackup

Share this post


Link to post
Share on other sites



Angrysteel,

If Total files: and EndOfUvbackup appear nowhere else in the text, then _StringBetween should work: :D

#Include <String.au3>

$sText = _
"Backing up c:/med-edi/ME.BP.O/MENU.DRIVER" & @CRLF & _
"Backing up c:/med-edi/ME.BP.O/MENU.WINDOW" & @CRLF & _
"Backing up c:/med-edi/ME.BP.O/PC" & @CRLF & _
"Backing up c:/med-edi/ME.CF" & @CRLF & _
"Backing up c:/med-edi/ME.CF/.Type1" & @CRLF & _
"Backing up c:/med-edi/ME.CF/01.SND" & @CRLF & _
"Backing up c:/med-edi/ME.CF/DSM01.SND" & @CRLF & _
"Backing up c:/med-edi/ME.CF/EDISTAT.txt" & @CRLF & _
"Backing up c:/med-edi/ME.CF/STO.449200" & @CRLF & _
"WARNING: The magic number of this file is byte-swapped, indicating" & _
"the file did not originate on this platform." & @CRLF & _
"Saving as SYSTEM type file!" & @CRLF & _
"Backing up c:/med-edi/ME.CTL" & @CRLF & _
"Backing up c:/med-edi/ME.POPF" & @CRLF & _
"Backing up c:/med-edi/ME.TPF" & @CRLF & _
"Backing up c:/med-edi/reg" & @CRLF & _
"Backing up c:/med-edi/reg/dump.REG.RTF" & @CRLF & _
"Backing up c:/med-edi/reg/REG.RTF" & @CRLF & _
"Backing up c:/med-edi/TEMP" & @CRLF & _
"Backing up c:/med-edi/USER.MPQ" & @CRLF & _
"Backing up c:/med-edi/USER.MPQ/.Type1" & @CRLF & _
"Backing up c:/med-edi/VOC" & @CRLF & _
"Backing up c:/med-edi/VOCLIB" & @CRLF & _
"" & @CRLF & _
"Total files: 241 Total bytes : 8087823 Elapsed Time: 00:00:05" & @CRLF & _
"222 operating system files processed, 0 broken, totalling 405313 data bytes." & @CRLF & _
"19 UniVerse files processed, 0 corrupted." & @CRLF & _
"36666 UniVerse records processed, 0 corrupted, totalling 7682510 data bytes." & @CRLF & _
"0 extended keys processed, 0 not supported at specified revision level." & @CRLF & _
"" & @CRLF & _
"EndOfUvbackup"

$aExtract = _StringBetween($sText, "Total files: ", "EndOfUvbackup")

MsgBox(0, "Extract", $aExtract[0])

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Angrysteel,

If Total files: and EndOfUvbackup appear nowhere else in the text, then _StringBetween should work: :D

#Include <String.au3>

$sText = _
"Backing up c:/med-edi/ME.BP.O/MENU.DRIVER" & @CRLF & _
"Backing up c:/med-edi/ME.BP.O/MENU.WINDOW" & @CRLF & _
"Backing up c:/med-edi/ME.BP.O/PC" & @CRLF & _
"Backing up c:/med-edi/ME.CF" & @CRLF & _
"Backing up c:/med-edi/ME.CF/.Type1" & @CRLF & _
"Backing up c:/med-edi/ME.CF/01.SND" & @CRLF & _
"Backing up c:/med-edi/ME.CF/DSM01.SND" & @CRLF & _
"Backing up c:/med-edi/ME.CF/EDISTAT.txt" & @CRLF & _
"Backing up c:/med-edi/ME.CF/STO.449200" & @CRLF & _
"WARNING: The magic number of this file is byte-swapped, indicating" & _
"the file did not originate on this platform." & @CRLF & _
"Saving as SYSTEM type file!" & @CRLF & _
"Backing up c:/med-edi/ME.CTL" & @CRLF & _
"Backing up c:/med-edi/ME.POPF" & @CRLF & _
"Backing up c:/med-edi/ME.TPF" & @CRLF & _
"Backing up c:/med-edi/reg" & @CRLF & _
"Backing up c:/med-edi/reg/dump.REG.RTF" & @CRLF & _
"Backing up c:/med-edi/reg/REG.RTF" & @CRLF & _
"Backing up c:/med-edi/TEMP" & @CRLF & _
"Backing up c:/med-edi/USER.MPQ" & @CRLF & _
"Backing up c:/med-edi/USER.MPQ/.Type1" & @CRLF & _
"Backing up c:/med-edi/VOC" & @CRLF & _
"Backing up c:/med-edi/VOCLIB" & @CRLF & _
"" & @CRLF & _
"Total files: 241 Total bytes : 8087823 Elapsed Time: 00:00:05" & @CRLF & _
"222 operating system files processed, 0 broken, totalling 405313 data bytes." & @CRLF & _
"19 UniVerse files processed, 0 corrupted." & @CRLF & _
"36666 UniVerse records processed, 0 corrupted, totalling 7682510 data bytes." & @CRLF & _
"0 extended keys processed, 0 not supported at specified revision level." & @CRLF & _
"" & @CRLF & _
"EndOfUvbackup"

$aExtract = _StringBetween($sText, "Total files: ", "EndOfUvbackup")

MsgBox(0, "Extract", $aExtract[0])

M23

Wow I was searching the help file and online for a good amount of time and didn't come across that. Thank you!!!!

Share this post


Link to post
Share on other sites

I would probably use

StringRegExp

--------------------------------------------------------------------------------

Check if a string fits a given regular expression pattern.

StringRegExp ( "test", "pattern" [, flag ] [, offset ] ] )

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I came up with this, which works as long as it's the last 7 lines that are wanted.. StringBetween, which I eventually would have thought of, is more 'flexible' in that regard..

#include <file.au3>
Local $aRecords
_FileReadToArray("logfile.txt",$aRecords)
$y = $aRecords[0] - 7
#cs
For $x = $y To $aRecords[0]
    ConsoleWrite($aRecords[$x] & @LF)
Next
#ce
_FileWriteFromArray("logfileresult.txt", $aRecords, $y, $aRecords[0])
Run("notepad.exe " & "logfileresult.txt")
Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
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
Sign in to follow this  
Followers 0