![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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, I'm thinking of another array? Any easier and quick solution. TIA |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |