Jump to content

search, found, copy ...thanks


koenp
 Share

Recommended Posts

Hello everybody,

I am looking for some help from the experts..(not me)

I want to make a kind of log analyser...

can anybody help me so example codes for :

First the script should look for a string in different filenames on different locations, and each time that string has been found the script should

copy the hole line where the string was found to an other new generated file...

Any ideas how to start on this?

Many thanks for all your help...

Kindly Regards,

Koen

Link to comment
Share on other sites

Hello, and welcome to the forum.

It's hard to get too specific without knowing details of your requirements, but...

You should work out some pseudo-code up front, get the main logic flow and functions of the program layed out.

For instance you might first need a table (array) of all the different files that you need to search.

You could hard-code that into your source when you declare the array, or, if the values may change on occasion, load the table from a file.

Then your main section might need an outer loop that would process one file per pass, and an inner loop to process each line of the current file. A test inside the inner loop, if met, could call a separate function that would write a line to your output file.

Start small and build upon it. Maybe just do the inner loop at first. Have it scan each line of a single file and temporarily just call a Msgbox(0,"", "String found in line " & $x) when it gets a hit. Once working, wrap an outer loop around that that will vary the input file each pass. Then replace the "found!" message with an I/O routine to create your results file.

Shouldn't be anything too complicated in there... just For-Next loops, FileOpen, FileReadLine, StringInStr, FileWriteLine, FileClose, etc. There are basic coding examples for all in the help file (the FileReadLine example might be a good start for your script).

Put something together, and if you're having trouble, post what you have and many here will be happy to help you fix it :graduated:

Edited by Spiff59
Link to comment
Share on other sites

From what you describe, this should do it:

#include <File.au3>
 
$logFile = "log.log"
$textToFind = "text"
$newFile = "New_File.txt"
 
$logFileLength = _FileCountLines($logFile)
For $i = 1 to $logFileLength Step 1
    $readLine = FileReadLine($logFile, $i)
    If StringInStr($readLine, $textToFind) Then
        FileWrite($newFile, $readLine & @CRLF)
    EndIf
Next

#include <ByteMe.au3>

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...