• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Using awk for pattern matching with regular expressions

Yohhan

Senior member
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.
 
Back
Top