I’m writing a script that needs to find an exact match in a file that is compatible with QNX and POSIX compliant Linux
more detail:
Im trying to find the user of a process so the original command I wrote was
user=$(ps -aux | awk '{print $1 " " $2}' | grep -w ${process} | awk '{}print $1')
which works perfectly in POSIX compliant Linux
however, QNX isn’t totally POSIX compliant and grep -w
isn’t usable for my target…so I need to find an exact match without grep -w
Advertisement
Answer
I think you want to print field 1 if field 2 exactly matches something:
ps -aux | awk -v p=$process '$2==p{print $1}'