Awk script to add times.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk script to add times.
# 1  
Old 05-06-2008
Awk script to add times.

Hey,

Im trying to format the last command to tell me just the user names, logins, and the time that they were logged in. So far I got the users logins using a loop that counts the amount of times a user logged in but im not sure how to start the time array. The time im trying to use is the last field when the last command is entered. Any help would be appreciated.

Here is some code I have atm:
Code:
BEGIN{print "USER" "\t" "LOGINS" "\t" "TIME"}
{count[$1]++}
END {
        for (name in count)
         print name "\t   " count[name]
}

Thanks for reading.
# 2  
Old 05-06-2008
I presume you want to display cumulative times for each user? Try using the split() function to pull out the components of the time field, and convert it to minutes, and add it to time[$1]. Then convert it back to d+hh:mm format when you are ready to print it.
# 3  
Old 05-08-2008
Sounds like a homework assignment I once had. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed add space X times

Pattern: Mary walks at the park every day with her children sed 's/$/ /' will make it add 1 space at the end (trailing) I want to add X ($VARIABLE) number of spaces (which comes from RANDOM) i.e. VARIABLE='14' then it will do: sed 's/$/ /' = 14 spaces added at the... (10 Replies)
Discussion started by: holyearth
10 Replies

2. Shell Programming and Scripting

Sed or Awk for lines between two strings multiple times and keep the last one

Hi, I am trying to get lines between the last occurrences of two patterns. I have files that have several occurrences of “Standard” and “Visual”. I will like to get the lines between “Standard” and “Visual” but I only want to retain only the last one e.g. Standard Some words Some words Some... (4 Replies)
Discussion started by: damanidada
4 Replies

3. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

4. Shell Programming and Scripting

AWK Duplicate lines multiple times based on a calculated value

Hi, I'm trying to create an XML sitemap of our dynamic ecommerce sites SEO Friendly URLs and am trying to create the initial page listing. I have a CSV file that looks like the following and need duplicate the lines based on a value which needs calculating. ... (2 Replies)
Discussion started by: jamesfx
2 Replies

5. Shell Programming and Scripting

awk - find average interarrival times for each unique page

All, I have a test file as specified below. 1st col is <arrival time> and 2nd col is <Page #>. I want to find the inter-arrival time of requests for each page # (I've done this part already). Once I have this, I want to calculate the average interarrival time. Note, that I am trying to have the... (11 Replies)
Discussion started by: jontjioe
11 Replies

6. Shell Programming and Scripting

How to make AWK process an input file many many times?

By "many many times" I mean the times the input file is to be processed is unknown beforehand, it will be known when awk finishes processing the input file for the first time. So my question is: how to start over again from the first record of the input file when AWK finishes processing the... (7 Replies)
Discussion started by: kevintse
7 Replies

7. Shell Programming and Scripting

Reading a file several times with awk

Hi everyone, I was wondering if it's possible to read a file ("file2" in my example) more than once. In this example I want to print file2 entirely for each lines of file1: awk -F$'\t' '{ print $0 while ((getline < "file2") > 0) { print "\t"$0 } }' file1 It... (4 Replies)
Discussion started by: anthony.cros
4 Replies

8. Shell Programming and Scripting

Add missing times

Not sure about the title if someone has a better name for it please lemme know and I will edit the title. I have several (10+ files) which look something like: File 1: 12/28/2009 04:0 8 12/28/2009 04:4 4 12/28/2009 05:0 4 . . . File 2: 12/28/2009 04:1 7 12/28/2009 04:2 3... (2 Replies)
Discussion started by: jstrangfeld
2 Replies

9. Shell Programming and Scripting

AWK print a character many times

How can I print a '-' on the same line within awk, say 50 times, without actually typing '-' 50 times? Cheers (3 Replies)
Discussion started by: dbrundrett
3 Replies
Login or Register to Ask a Question