associative arrays?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting associative arrays?
# 1  
Old 02-07-2011
associative arrays?

Hello,
i'm writing a little script that checks a .txt file for a specific ID that came after 9:10 am which outputs it's data to a file LateUsers.txt
once done , it should mention the following:

  1. Number of late users
  2. Number of unique late users
  3. Over all late users percentage
  4. number of days each user is late
  5. send an email to each users with his status ( if late to inform him and if not to just state his hours)
what i'm asking for advice with is point 4 and a part of number 5
more specifically can i have an associative array with 3 fields?
for example:

user1 has a Name an ID and an Email
that way i could grep for ID and then grep for tht id to show the name and then use the email of that record to send him an email (i dont have a prob with the mail step)

find below my start up script :

Code:
more a*.txt | awk -F, '{if($2 != "X" && !a[$3]) {a[$3]++;if($4 > "09:10:00") print "ID number " $2 " came in on",substr($3,6,5)," at",substr($4,0,5),"after 09:10";}}' > ./LateUsers.txt;
echo "######################################################"
more ./LateUsers.txt;
echo "######################################################"
NumberOfLateUsers=$(more LateUsers.txt |  cut -d ' ' -f3 | sort | uniq | wc -l)
echo
echo "number of late users is $NumberOfLateUsers"
echo "######################################################"
echo "which have the following IDs: "
echo
more LateUsers.txt |  cut -d ' ' -f3 | sort | uniq
echo "######################################################"
echo
Percentage=`expr $NumberOfLateUsers \\* 100 \/ 27`
echo "Percentage of overall late users is:  $Percentage %"
echo "######################################################"
~                                                                                                                                                                           
~                                                                                                                                                                           
~

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using associative array for comparison

Hello together, i make something wrong... I want an array that contains information to associate it for further processing. Here is something from my bash... You will know, what I'm trying to do. I have to point out in advance, that the variable $SYSOS is changing and not as static as in my... (2 Replies)
Discussion started by: Decstasy
2 Replies

2. Shell Programming and Scripting

Associative arrays awk

Hi, I have the following dataset. A 2 1 272 A 2 2 333 A 2 3 222 A 3 1 222 A 3 2 11 B 1 1 112 B 1 2 998 B 2 1 667 C 1 1 887 C 1 2 887 C 2 1 998 I need to have an associate array based on the first column and generate a auto generated number column in the last column. Needed output:... (2 Replies)
Discussion started by: mitt
2 Replies

3. Shell Programming and Scripting

Associative array

I have an associative array named table declare -A table table="fruit" table="veggie" table="GT" table="eminem" Now say I have a variable returning the value highway How do I find corresponding value GT ?? (this value that I find (GT in this case) is supposed to be the name of a mysql... (1 Reply)
Discussion started by: leghorn
1 Replies

4. Shell Programming and Scripting

Improving code by using associative arrays

I have the following code, and I am changing it to #!/bin/bash hasArgumentCModInfile=0 hasArgumentSrcsInfile=0 hasArgumentRcvsInfile=0 OLDIFS="$IFS" IFS="|=" # IFS controls splitting. Split on "|" and "=", not whitespace. set -- $* # Set the positional... (3 Replies)
Discussion started by: kristinu
3 Replies

5. UNIX for Dummies Questions & Answers

Using associative arrays with an if statement

I have this piece of code. The first if statement is not working, however the second if statement is working fine. I have set a value for Srcs to be file.srcs and want to print it. If no value for Rcvs is set, I get the print statement correctly hasValue="file.srcs" if ${hasValue}; then ... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

7. Shell Programming and Scripting

Associative arrays

Hi all, #!/usr/dt/bin/dtksh typeset -A wavelength wavelength=650 wavelength=590 wavelength=510 wavelength=475 wavelength=445 wavelength=400 I have created an associative array like the one above. Now I am trying to print the values If i give print ${wavelength} it is... (4 Replies)
Discussion started by: prasperl
4 Replies

8. UNIX for Dummies Questions & Answers

Unable to understand associative nature of awk arrays

About associative nature of awk arrays i'm still confused, not able to understand yet how array element can be accessed based on a string, I got one example at gawk manual to illustrate associative nature of awk arrays, it goes here: Codeawk ' # Print list of word frequencies { for (i = 1;... (3 Replies)
Discussion started by: nervous
3 Replies

9. UNIX for Dummies Questions & Answers

are Associative Arrays possible in UNIX?

Is it possible to say.. myArr=34 myArr=15 ? (11 Replies)
Discussion started by: yongho
11 Replies

10. Shell Programming and Scripting

Associative Array

Hi, I am trying to make an associative array to use in a popup_menu on a website. Here is what i have: foreach $entr ( @entries ) { $temp_uid = $entr->get_value(uid); $temp_naam = $entr->get_value(sn); $s++; } This is the popup_menu i want to use it in. popup_menu(-name=>'modcon',... (4 Replies)
Discussion started by: tine
4 Replies
Login or Register to Ask a Question