0

Given a file of lines of the following format, I want to print those lines who have a time greater than X seconds.

2015-08-03 00:43:01, time taken to run = 10 seconds

How can I use a single line of awk to achieve this? Thanks!

2 Answers 2

3

Assuming that the number of seconds is always in the penultimate field, you could use something like this:

awk '$(NF-1) > 5' file 

NF is the number of fields, so $(NF-1) gets the value of the second to last field. If the value is greater than 5, the line is printed.

To use a shell variable instead, you can do something like this:

m=5 awk -v max="$m" '$(NF-1) > max' file 
Sign up to request clarification or add additional context in comments.

Comments

0

If your log format is fixed, you can do this. For example greater than 9.

awk '/time taken to run/ && $8>9' log.txt 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.