Skip to main content

awk + how to capture the third field on both characters [Resolved]

from ps ax we get the following output

 ps ax
   PID TTY      STAT   TIME COMMAND
     1 ?        Rs   611:56 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
     2 ?        S      4:46 [kthreadd]
     3 ?        R    3499:33 [ksoftirqd/0]
     5 ?        S<     0:00 [kworker/0:0H]
     7 ?        S     16:24 [migration/0]
     8 ?        S      0:00 [rcu_bh]
     9 ?        S      0:00 [rcuob/0]
    10 ?        S      0:00 [rcuob/1]
    11 ?        S      0:00 [rcuob/2]
    12 ?        S      0:00 [rcuob/3]
    13 ?        S      0:00 [rcuob/4]
    14 ?        S      0:00 [rcuob/5]
    15 ?        S      0:00 [rcuob/6]
    16 ?        S      0:00 [rcuob/7]
    17 ?        S      0:00 [rcuob/8]
    18 ?        S      0:00 [rcuob/9]
    19 ?        S      0:00 [rcuob/10]

so we want to capture the R on the third field for example

 ps ax | awk '$3 ~ /R/ { print }'
   139 ?        R    1935:31 [rcuos/1]

now we want both , to capture R and D on the third field

in this case what should be the syntax in order to capture ether R or D on the third field ?


Question Credit: yael
Question Reference
Asked March 25, 2019
Tags: , process
Posted Under: Unix Linux
15 views
1 Answers

Your Answer