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 Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 06:41 PM
awk arrays imonthejazz Shell Programming and Scripting 1 09-21-2007 10:29 AM
arrays in awk??? craigsky Shell Programming and Scripting 3 08-27-2007 10:13 PM
ksh script - arrays sidamin810 Shell Programming and Scripting 13 07-18-2005 04:07 AM
KSH and arrays whited05 Shell Programming and Scripting 1 06-24-2005 01:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-10-2001
nitin's Avatar
nitin nitin is offline
Registered User
  
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 88
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
  #2 (permalink)  
Old 12-10-2001
TioTony's Avatar
TioTony TioTony is offline Forum Advisor  
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0