#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    St. Louis, MO
    Posts
    7
    Rep Power
    0

    Using Korn Shell Pattern Matching


    I am using Korn shell too automatically run finger bfhp on an HPUX OS. The logins that are being used are from Active Directory and some contain spaces, others contain periods (.) and some contain both. I am trying to ignore those logins as they will create a memory leak on the system. I am having issues with the Regular Expression to filter this data out as it does not work. Can someone please look at this statement below and tell me what I am doing wrong:

    for i in `logins -o | awk -F: '{ print $1}'`
    do
    if $i != (\.|\s)
    then
    finger -bfhp $i >> /tmp/last_login.out
    done

    Thank you in advance!

    Mike
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    India
    Posts
    177
    Rep Power
    21

    filter data using grep


    You can't use regex like that in a shell; I think so!

    What you could do it filter the unwanted lines (i.e. ip having space e.g.) in the for header itself!

    Note that in the following, for rejects those ips having space in it!

    Code:
    for i in `cat logins | awk -F: '{ print $1}' | grep -v ' '`
    do
    echo $i
    finger $i >> /tmp/last_login.out
    done
    Use this as a apointer and modify your script

IMN logo majestic logo threadwatch logo seochat tools logo