Using awk for pattern matching with regular expressions

Yohhan

Senior member
May 17, 2002
263
0
0
I'm running an awk script against a file that contains the output of all the running processes on my system using ps -ef

The different fields are delimited by spaces. However, some of the fields, such as time have a ":" delimiter which makes the output look something like this:

1 somestuff 00:00:00
2 somestuff 00:00:00
3 somestuff 00:00:02
4 somestuff 00:00:00


I need to get the rightmost two digits from field $3, ie: "02" and "00". I'm trying to do this using a regular expression, and saving the matched two digits. However, I can't figure out how to save them. In perl, it'd look something like this:

$twodigits = ($psoutput =~ /\d\d:\d\d:(\d\d)/)

And the parenthesized digits would be saved into $twodigits (if I'm remembering that correctly). Does awk have a similar way to save pattern matches? Or is there an easier way for me to do this? I need to use awk, so perl isn't an option here.

Thanks ahead.