skip to Main Content

I have a log file "Apps.out" of an application for a WebLogic, there is a specific app that sends logs like this to that file:

[YYYY/MM/DD HH:MM:SS][INFO][PATTERN -> Information1]
[YYYY/MM/DD HH:MM:SS][INFO][PATTERN -> Information2]
[YYYY/MM/DD HH:MM:SS][INFO][PATTERN -> Information3]
[YYYY/MM/DD HH:MM:SS][INFO][PATTERN -> Information4]
[YYYY/MM/DD HH:MM:SS][INFO][PATTERN -> Information5]

I can filter this information with: grep ‘PATTERN’ Apps.out
but I want to send this information to a new file (app1.log) and do this progressive just to send the new register on app1.log that matches the PATTERN, is it possible to do it in real-time?
Thank you

2

Answers


  1. You can do it using tail -f:

    nohup bash -c "tail -f Apps.out | grep PATTERN > app1.log" &

    This will follow the file as it grows from the moment you start going back 10 lines.

    You can change that with -n and go back as many lines as wish or read from the start of the file.

    Login or Signup to reply.
  2. here is what you can do : <your_log_file> as your log file
    and <your_PATTERN> as you PATTERN

    nohup tail -f <your_log_file>.log|while IFS= read -r;do
        case $REPLY in
            (*<your_PATTERN>*)printf "%sn" "$REPLY">>app1.log;
        esac
    done &
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search