Skip to content
Advertisement

Parse ps’ “etime” output and convert it into seconds

These are possible output formats for ps h -eo etime

JavaScript

How to parse them into seconds?

  • Please assume at least 3 digits for the days part as I don’t know how long it can be.
  • The output will be egreped to one only line so no need for a loop.

Advertisement

Answer

With awk:

JavaScript

Run with :

JavaScript

Output:

JavaScript

And finally, if you want to pipe to the parser, you can do something like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement