Johsttin Curahua
Johsttin Curahua

Reputation: 11

Filter log and send the ouput to a new file in real time

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

Upvotes: 0

Views: 51

Answers (2)

NuLo
NuLo

Reputation: 1528

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.

Upvotes: 1

blackbird
blackbird

Reputation: 146

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 "%s\n" "$REPLY">>app1.log;
    esac
done &

Upvotes: 0

Related Questions