Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data chopping

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH

Hi ,

I m running the following command

who -u | nawk ' { if ( substr($5,1,2) > 9 ) print $0 }'

This is just to get the list of users who have logged on after 9. But this line comes back with nothing. At the same time if I just say

who -u | nawk ' { print substr($5,1,2) }'

It shows me the substr of the time and some of the records have time more than 9. So I fail to understand what its doing.

Any pointers please.

Thnx
 
You are comapring a string to a number. Try..

' { if ( int(substr($5,1,2)) > 9 ) print $0 }'
 
IMAUser,

If you want to find out who has logged in after 9:00, you should probably use:

who -u | awk ' { if ( int(substr($5,1,2)) >= 9 ) print $0 }'

because > 9 will only print lines that are greater than 9. Also keep in mind that this does not take into consideration the login date. Someone could have logged in the previous day after 9:00 and still be displayed on your listing.

John
 

Actually yes.

I have a few issues with the way I m checking. I need to add some flexibility. So the immediuate requirement is to find out who has logged in say in the last tow hours. so the "9" is not relevant but I need to somehow get the current time from the command date. I tried using date like you wud use it in a shell script
var=`date +%H` within the awk commmand but awk dosent like it. So I m stuck. Any ideas please..

Thnx,
 
Hi CaKiwi,

Where do I use it. If I had this on the command line

who -u | awk ' { if ( int(substr($5,1,2)) >= 9 ) print $0 }'

Where wud the getline var come.

Thanks
 
Something like

who -u | awk ' BEGIN{"date +%H" | getline var} { if ( int(substr($5,1,2)) >= var ) print $0 }'



CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top