1

I have some application that produce log file and at the end of file I have total processing time like:

Processing done in 45.00031 sec

I can get this line using:

cat app.log | grep "Processing done in" 

But how to parse string to get only number of seconds?

45.00031

3 Answers 3

1

If the pattern is set you can just use cut to select the 4th field from a space-delimited table:

cat app.log | grep "Processing done in" | cut -d " " -f 4
Sign up to request clarification or add additional context in comments.

Comments

0

grep again for only numbers and dot

cat app.log | grep "Processing done in" | grep -oE '[0-9.]+'

Be careful, it might stop working in another locale, that uses , as decimal separator.

Comments

0

Or, in 1 process instead of 3

 sed -n 's/^Pr.*in //;s/ sec//p' app.log

output

45.00031

IHTH

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.