-1

I'm looking to make a batch script. What I have is a ton of different logs in a ton of different places, all with a bit of important info and a lot of useless info.

Some of these logs are directly named, and some are named by date and time.

I'm trying to make a script that can basically scan them for me so I don't have to go through each folder and log and scan manually.

Some examples:

  • OmegaManager\logs\omega.log - scan for "State:" and "has been updated"
  • OmegaManager\logs\instance-0.log - scan for "shutdown"
  • KRBanking\PlayerDatabase*logs are numbers* - copy all information or scan for changes since last time?
  • KRBanking\ServerLogs*logs are dates and times* - scan for "Deposited" and "Withdrawed"

And then output the whole line.

Is this even moderately possible? Thanks in advance.

Christian
  • 4,902
  • 4
  • 24
  • 42
  • Welcome to SO. You could use a [for loop to go over the directories](https://stackoverflow.com/questions/138497/iterate-all-files-in-a-directory-using-a-for-loop) and use [findstr](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/findstr) to search for patterns of text in files. Please share your code if you have already tried something. SO is not a coding service, please read [how to ask](https://stackoverflow.com/help/how-to-ask). – Christian Aug 02 '22 at 20:52
  • Thanks. I asked if it was possible and it seems like it is using findstr. Can you direct me somewhere to a coding service because that's all I see on here so I'm sorry I didn't catch the memo. I don't know batch scripting at all so everything I find is the same chart of info over and over again but I'm not getting anywhere. I would LOVE to do it myself but I need a lot of help then. – Frankii Aug 02 '22 at 21:17
  • It's fun to learn to write batch files, you can automate so much. See my answer below for a start. – Christian Aug 02 '22 at 22:42

1 Answers1

1

Yes, this is possible. Batch files support loops, conditions, and filtering/searching.

A FOR loop allows you to iterate through files or directories, you'll find more information in this SO post.

To find strings in a file, you have several options, i.e. find and findstr, see riptutorial.com:

  • FIND can scan large files line-by-line to find a certain string with no wildcard support.
  • FINDSTR has more features and supports regular expressions with wildcards in the search string.

Super simple example for one of your use cases

The batch script must be placed where your files are. Otherwise, you need to add a full path instead of just "omega.log".

FINDSTR /L /C:"State:" /C:"has been updated" omega.log

To start with batch programming, you can read the findstr documentation and some tutorials.

Christian
  • 4,902
  • 4
  • 24
  • 42