Script to extract line from logfile

Try changing

sub(/logfile_systemdat.log/, "test.txt", FILELOG)

to

sub(/\/*\.log$/, "/test.txt", FILELOG)

This should cause the test.txt file to be created. If there are more that one log file per path then you will only have a test.txt for the last log file processed.

Hi JP,

I made the changes as you suggested and executed the script.

$ awk -f log.awk gtest/svtaree/*
awk: log.awk:32: (FILENAME=gtest/svtaree/access_07.09.09.log FNR=111) fatal: can't redirect to `gtest/svtaree/access_07.09.09/test.txt' (No such file or directory)

$ awk -f log.awk gtest/*/*
awk: log.awk:32: (FILENAME=gtest/svtaree/access_07.09.09.log FNR=111) fatal: can't redirect to `gtest/svtaree/access_07.09.09/test.txt' (No such file or directory)

It did create a file access_07.09.09.log.strip.
The script this time copied the other entries and copied to access_07.09.09.log.strip, leaving the GuestUser entries in the original file.
And it looks like it took only the first logfile in the path.

I forgot one of the attributes of the sub command, so I made a correction.

Replace the sub command with:

  s = split(FILELOG, a, "/")
  sub(a "$", "test.txt", FILELOG)

This sequence doesn't care what the log file is named.

You will need a wrapper script to process archive files (i.e. tar or zip) before giving them to awk.

And it only processed the first file because awk terminated after the error.

Make sure you restore the log files before each test run of the script.

Hey JP,

The changes worked.
It created the test.txt for each server.Excellent

Thanks,
Garry

Hi JP,

Did you get time to create the final script ?
Waiting for your update.

Thanks,
Garry

Garry,

The script is done. What is left is for you to understand cron. Do a man on crontab and email me using the private mail if you have questions. TIme for me to move on....

jp