What shell / OS?
If you're using bash, you should be able to get away with something like:
Code:
#! /bin/bash
typeset -i n=0
typeset -a names
oldifs="$IFS"
IFS=:
while read passwdname _; do
[[ $passwdname == *a* ]] && names[n++]=$passwdname
done </etc/passwd
IFS="$oldifs"
names=${names[*]}
ps --o user,fname -U ${names// /,}
Or:
Code:
ps --o user,fname | gawk '/^[^ ]*ram/{print $1}'
I'm sure there's a dozen ways of doing this better, but those are the first two things I thought of.