The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-24-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool Perhaps someone might clean this up a bit

The following works, but not sure if all necessary.

Code:
#! /usr/bin/bash

who | awk '{line[$1] = $1
     sum[$1]++}
    END{
     for(i in sum)
     if (sum[i]>0)
       print line[i]
}'
set array variable to the first read (which is name) field
increment a counter so I can know if anything in array value

step thru all values in my sum array
if the value in sum > 0 (meaning I have a match)
print out the corresponding entry in the line array

Last edited by joeyg; 10-24-2008 at 04:17 PM.. Reason: added some explanation