Denys
Denys

Reputation: 4557

Parsing entry name from a log

Writing bash parsing scripts is my own personal nightmare, so here I am.

The server log format is below:

197 INFO    Thu Mar 27 10:10:32 2014
    seq_1_1..JobControl (DSWaitForJob): Waiting for job job_1_1_1 to finish
198 INFO    Thu Mar 27 10:10:36 2014
    seq_1_1..JobControl (DSWaitForJob): Job job_1_1_1 has finished, status = 3 (Aborted)
199 WARNING Thu Mar 27 10:10:36 2014
    seq_1_1..JobControl (@job_1_1_1): Job job_1_1_1 did not finish OK, status = 'Aborted'

From here I need to parse out the string which follows the format:

Job job_name has finished, status = 3 (Aborted)

So from the output above I should get: job_1_1_1

What would the script for that look like if I get this server log as a certain command output?

Thanks xx

Upvotes: 1

Views: 50

Answers (1)

anubhava
anubhava

Reputation: 784998

Using grep -P:

grep -oP '\w+(?= has finished, status = 3)' file
job_1_1_1

Upvotes: 2

Related Questions