The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help with awk and arrays fusionX Shell Programming and Scripting 7 02-11-2008 03:41 PM
awk arrays imonthejazz Shell Programming and Scripting 1 09-21-2007 06:29 AM
arrays in awk??? craigsky Shell Programming and Scripting 3 08-27-2007 06:13 PM
ksh script - arrays sidamin810 Shell Programming and Scripting 13 07-18-2005 12:07 AM
KSH and arrays whited05 Shell Programming and Scripting 1 06-24-2005 09:07 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-09-2001
nitin's Avatar
Registered User
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 56
Two or more arrays in Awk

Hi All,
I have been working on awk and arrays. I have this small script:

cat maillog*|awk -F: '$2=="SMTP-Accept" && $5~/string/ {lastdate=substr($1,1,8); internaluser=$5; v[internaluser]++} END {for (j in v) {print lastdate, v[j], j}'| sort>> mail.list

This gives me the number of mails users are getting. But there is one flaw, the date is same for all the users. The date field printed out is the very last date it picks and puts it for everyone. Is there a way to save the "last-date" for every user somewhere and print it?
I'm thinking of another array? Any easier and quick solution.
TIA
Forum Sponsor
  #2  
Old 12-10-2001
TioTony's Avatar
Bit Pusher
 

Join Date: Oct 2001
Location: Southern California
Posts: 332
Hi Nitin,
I think the reason your dates are all the same is because your print lastdate statement is in the END section of the awk script. This means awk will print what ever the value of lastdate is for the last record. You can confirm this by looking at the date for the last input record and see if that is the same as your script output.
Sorry I don't know how to fix this. I am not sure how you would do a multi-dimensional array in awk, but I am sure it can be done. Your idea of 2 arrays may work as well but you will have to ensure the rows line up correctly so user1 doesn't display user2's lastdate.
Good Luck,
TioTony
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0