Sponsored Content
Full Discussion: Helpm with time function
Homework and Emergencies Homework & Coursework Questions Helpm with time function Post 302988395 by jim mcnamara on Sunday 25th of December 2016 05:15:31 PM
Old 12-25-2016
This is some awk code. Because you wanted to add days to lines where it could not be calculated, this code is two awk scripts in one bash script. It could be cleaned up.
It adds -1 to lines in error, error being a singleton line.
Code:
$ cat filename && ./t.awk
7  65  2    5   32070  2010-12-14    13:25:30
7  82  2    10  41920  2010-12-14    11:30:45
7  83  1    67  29446  2010-12-14    04:15:25
7  81  1    47  32070  2011-5-11      08:14:20
7  83  1    67  29446  2011-6-22      07:13:24
7  82  2    10  41920  2011-5-14      06:15:25
7  82  2    10  41921  2011-5-14      06:15:25

7  65  2    5   32070  2010-12-14    13:25:30   147
7  82  2    10  41920  2010-12-14    11:30:45 150
7  83  1    67  29446  2010-12-14    04:15:25   189
7  81  1    47  32070  2011-5-11      08:14:20 147
7  83  1    67  29446  2011-6-22      07:13:24     189
7  82  2    10  41920  2011-5-14      06:15:25 150
7  82  2    10  41921  2011-5-14      06:15:25 -1

Code:
# 7  82  2    10  41920  2011-5-14      06:15:25


awk '{
       split($6,arr,"-")
       a=sprintf("%s %s %s 0 0 0",arr[1], arr[2], arr[3])
       d=mktime(a)
       # this is to handle the fact that you want the same data early and late 
       # in the output
       delta[$5]=delta[$5] " " d
     } 
     END {for(i in delta) {print i, delta[i]}  }'  filename > tmp.dat

#    
# display output, print error "-1" if each $5 does not occur twice in the input file
awk '{
      if (FILENAME=="tmp.dat" )
      { 
        delta[$1]=$0; 
        next
      }
      if (FILENAME=="filename")
      { 
        a="-1"  # default is error
        if($5 in delta)
        {
           cnt=split(delta[$5],arr)
           if(cnt==3) # correct number, 1 for $5 two & three are epoch seconds
           {
             a=arr[3] - arr[2]
             a/=86400
             a=int(a)
           }
        }
        print $0, a      
        next
      }
    }' tmp.dat filename   
# note the order of files here is important

This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

C time in milliseconds function.

I need a c function which return the time in: hour min sec and mil sec I am writing on unix os. (3 Replies)
Discussion started by: kamil
3 Replies

2. Programming

find CPU Time for a function (subsecond precision)

Hi, I need to time a certain function in my C/C++ code and I am experiencing some difficulties. I timed it using wallclock time so I know that it takes approximately 500-600 microseconds with gettimeofday(&start, NULL); // my function call gettimeofday(&end, NULL); answer = (end.tv_sec -... (2 Replies)
Discussion started by: zynnel
2 Replies

3. Shell Programming and Scripting

time function

Hi, I would like to display the exact time taken to complete running a particular tool or function or program to user I don't know the exact time functions in unix, please help me thanks in advance Example: $test.ksh output should be The... (10 Replies)
Discussion started by: hsekol
10 Replies

4. Programming

function time

Hello I have problem with function 'time' to test my program for file copying . How to run the function in my source code ? I try something like that: system("time"); < -- but this don't working (2 Replies)
Discussion started by: scotty_123
2 Replies

5. Shell Programming and Scripting

Nawk Time Function

Hi All, I am using solaris and nawk. Is there any time function in nawk which is simliar to the shell `date` function ? Can any experts show any examples? (4 Replies)
Discussion started by: Raynon
4 Replies

6. Shell Programming and Scripting

Unix function to calcuate the difference in time

HI , I need to get the timedifference between two values... which funcation will help eg: difference betweem 19:22 and 19:43 should give 21 mins (2 Replies)
Discussion started by: savitha
2 Replies

7. UNIX for Dummies Questions & Answers

time function

hello everybody! i want to post a question. So, I use the command 'time a.out' to time the duration of the program a.out. The return value of this function was: real 0m4.116s user 0m4.112s sys 0m0.016s What i want is! I try to find a way to get (NOT manually) the value of real time.... (2 Replies)
Discussion started by: nicos
2 Replies

8. Red Hat

lightweight function for measuring time ( better than clock_getime )

HI I have a Red Hat Enterprise with Real Time kernel. Are you aware if there are C functions for this kernel or some code/library for this OS for measuring time more lightweight than clock_gettime and gettimeofday? THe hardware I have is NUMA. Reading forums I found gethrtime but it is... (1 Reply)
Discussion started by: manustone
1 Replies

9. Shell Programming and Scripting

/usr/bin/time Shell Scripting Function

Hello, I have made a Linux Shell Script that downloads 6 files from the Internet and then deletes them. Now i want to use the function "/usr/bin/time" and "bc" to calculate how long the avergate run time for the shell script is. I therefore need to do it 100 times. My shell script code is below: ... (6 Replies)
Discussion started by: solo2
6 Replies

10. OS X (Apple)

'time' does NOT work on a function in 'dash'.

Hi guys and gals... I am writing a piece of code that is dash compliant and came across this error. I have put it in the OSX section as that is what I am using. I have no idea what the 'dash' version is but was installed about 6 months ago. MBP, OSX 10.12.6, default terminal running dash on... (4 Replies)
Discussion started by: wisecracker
4 Replies
sccs-rmdel(1)							   User Commands						     sccs-rmdel(1)

NAME
sccs-rmdel, rmdel - remove a delta from an SCCS file SYNOPSIS
rmdel -rsid s.filename... DESCRIPTION
The rmdel utility removes the delta specified by the SCCS delta ID (SID) supplied with -r. The delta to be removed must be the most recent (leaf) delta in its branch. In addition, the SID must not be that of a version checked out for editing: it must not appear in any entry of the version lock file (p.file). If you created the delta, or, if you own the file and directory and have write permission, you can remove it with rmdel. If a directory name is used in place of the s.filename argument, the rmdel command applies to all s.files in that directory. Unreadable s.files produce an error; processing continues with the next file (if any). The use of `-' as the s.filename argument indicates that the names of files are to be read from the standard input, one s.file per line. OPTIONS
The following option is supported: -rsid Remove the version corresponding to the indicated SID (delta). ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of rmdel: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. FILES
p.file permissions file s.file history file z.file temporary copy of the s.file ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsprot | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
sccs(1), sccs-admin(1), sccs-cdc(1), sccs-comb(1), sccs-delta(1), sccs-help(1), sccs-prs(1), sccs-prt(1), sccs-sccsdiff(1), sccs-unget(1), what(1), sccsfile(4), attributes(5), environ(5), standards(5) DIAGNOSTICS
Use the SCCS help command for explanations (see sccs-help(1)). SunOS 5.11 2 Jul 2007 sccs-rmdel(1)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy