The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 11-21-2007
LivinFree's Avatar
LivinFree LivinFree is offline
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
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.
Reply With Quote