Sponsored Content
Top Forums UNIX for Advanced & Expert Users Subtract millisecond Timestamps with awk Post 303025079 by RudiC on Tuesday 23rd of October 2018 05:10:19 PM
Old 10-23-2018
Quote:
Originally Posted by sidnow
How should I do that?
Now - how many minutes does an hour have? And how many seconds a minute? Do you know about awk's split command?


BTW, your attempt will print nothing if the hours are the same, and the input line if different.

Last edited by RudiC; 10-23-2018 at 06:15 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

Help! Display Time with Millisecond

Hi All, Urgent! Just a newbie needing advice. Has anybody have a sample C script code in Unix to display time with milliseconds? Most of the research I'm doing is up to the seconds format only. Thanks! Leidail (3 Replies)
Discussion started by: rezlez
3 Replies

2. Shell Programming and Scripting

How to find date Difference in AWK/GAWK with millisecond precision

Hi, I have a log file that has the date in this format "2006-05-30_13:14:04,256". I need to find the time difference between two log entries in milliseconds. How to achieve this in AWK/GAWK script? :confused: (2 Replies)
Discussion started by: omprasad
2 Replies

3. Shell Programming and Scripting

AWK solution to subtract multiple columns of numbers

Hope somebody is happy. NR==1 { num_columns=split( $0, menuend ); next; } { split( $0, substrend ); for ( i=1; i<=NF; i++ ) { minuend -= substrend; } } END { print "Result:"; for ( i=1; i<=num_columns; i++ ) { printf(... (3 Replies)
Discussion started by: awkward
3 Replies

4. Shell Programming and Scripting

add and subtract specific row using awk

Hi Folks I have tried awk command to conditionally add or subtract value from specific row in a file. The test file looks like: # cat test.txt cont x y Max 0.3 0.9 Min 0.2 0.9 diff 0.1 0 # awk '{for (i=2; i <=NF; i++) if ($i== "0") $i=$i+0.2; print}' test.txt Output: cont... (1 Reply)
Discussion started by: dixits
1 Replies

5. Shell Programming and Scripting

Get timestamp with millisecond precision

Hi All, could any body let me know. how to get timestamp with millisecond precision in unix bash shell. example -->2005-12-06- 4-22-35-195 please help me. Thanks, Krupa:wall: (3 Replies)
Discussion started by: krupasindhu18
3 Replies

6. Shell Programming and Scripting

Compare & subtract lines in files by column using awk.

I have two files with similar column pattern as given below : 2 sample lines from file1 are given below. 18 12630 . G T 49.97 . AC=2;AF=1.00;AN=2;DP=3;Dels=0.00;FS=0.000;HRun=0;HaplotypeScore=0.0000;MQ=60.00;MQ0=0;NDA=1;QD=16.66;SB=-0.01 GT:AD:DP:GQ:PL ... (2 Replies)
Discussion started by: vaibhavvsk
2 Replies

7. Shell Programming and Scripting

To print lines between 2 timestamps using awk|sed and regex

Hi, I am using the following code to fetch lines that are generated in last 1 hr . Hence, I am using date function to calculate -last 1 hr & the current hr and then somehow use awk (or sed-if someone could guide me better) with some regex pattern. dt_1=`date +%h" "%d", "%Y\ %l -d "1 hour... (10 Replies)
Discussion started by: sarah-alikhan31
10 Replies

8. UNIX for Dummies Questions & Answers

awk to add/subtract an integer to/from each entry in columns?

---------- Post updated at 01:58 PM ---------- Previous update was at 01:48 PM ---------- For some reason my question is not getting printed. Here are the details: Greetings. I would like to add/subtact an integer to/from two columns of integers. I feel like this should be easy using awk... (3 Replies)
Discussion started by: Twinklefingers
3 Replies

9. Shell Programming and Scripting

awk to subtract from values in file

data.txt: 0,mq_conn_open_error,1444665949,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,733--734 0,mq_conn_open_error,1444666249,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,734--734... (7 Replies)
Discussion started by: SkySmart
7 Replies

10. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies
utc(1m) 																   utc(1m)

NAME
utc - A dcecp object that manipulates UTC timestamps SYNOPSIS
utc add timestamp relative_timestamp utc compare absolute_timestamp absolute_timestamp [-noinaccuracy] utc convert absolute_timestamp [-gmt] utc help [operation | -verbose] utc multiply relative_timestamp {integer | floating_point_factor} utc operations utc subtract timestamp timestamp ARGUMENTS
An International Organization for Standardization (ISO) compliant time format of the following form: CCYY-MMDD- hh:mm:ss.fff[+|-]hh:mmIsss.fff The Time Differential Factor (TDF) component [+|-]hh.mm, if present, indicates the offset from Universal Time Coordinated (UTC) time and implies local system time. The inaccuracy component Iss.fff, if present, specifies the duration of the time interval that contains the absolute time. A floating-point number such as 53.234. A whole number such as 79. The name of the utc operation for which to display help information. A Distributed Time Service (DTS) timestamp of the following form: [-]DD-hh:mm:ss.fff- Iss.fff Relative times often omit fractions of seconds (the leftmost .fff sequence) and generally lack an inaccuracy component (Iss.fff). For example, a relative time of 21 days, 8 hours, and 15 minutes is expressed as 21-08:15:00. A utc timestamp that can be a relative or absolute time. See the relative_timestamp and absolute_timestamp argument descriptions for the format of these timestamps. DESCRIPTION
The utc object lets you add, compare, and convert timestamps in DTS and ISO formats. OPERATIONS
utc add Adds two timestamps. The syntax is as follows: utc add timestamp relative_timestamp The add operation returns the sum of two timestamps. The timestamps can be two relative times or an absolute time and a relative time. Privileges Required No special privileges are needed to use the utc add command. Examples dcecp> utc add 1994-10-18-13:21:50.419-04:00I----- +0-00:02:00.000I----- 1994-10-18-13:23:50.419-04:00I----- dcecp> utc compare Compares two absolute timestamps indicating the temporal order. The syntax is as follows: utc compare absolute_timestamp absolute_time- stamp [-noinaccuracy] The compare operation compares two timestamps and returns -1 if the first is earlier, 1 if the second is earlier, and 0 if the difference is indeterminate. Specify the -noinaccuracy option to ignore inaccuracies in comparisons; in this case a return of 0 indicates the times are the same. Privileges Required No special privileges are needed to use the utc compare command. Examples dcecp> utc compare 1994-10-18-13:22:32.816-04:00I----- > 1994-10-18-13:21:50.419-04:00I----- -noinaccuracy 1 dcecp> utc convert Converts a timestamp from UTC to local time. The syntax is as follows: utc convert absolute_timestamp [-gmt] The convert operation accepts a timestamp and returns another timestamp that expresses the same time in the local time zone. If called with the -gmt option it returns a Greenwich mean time (GMT) formatted timestamp. Privileges Required No special privileges are needed to use the utc convert command. Examples dcecp> utc convert 1994-10-18-13:22:32.816-00:00I----- 1994-10-18-09:22:32.816-04:00I----- dcecp> dcecp> utc convert 1994-10-18-13:22:32.816-00:00I----- -gmt 1994-10-18-13:22:32.816I----- dcecp> utc help Returns help information about the utc object and its operations. The syntax is as follows: utc help [operation | -verbose] Options Displays information about the utc object. Used without an argument or option, the utc help command returns brief information about each utc operation. The optional operation argu- ment is the name of an operation about which you want detailed information. Alternatively, you can use the -verbose option for more detailed information about the utc object itself. Privileges Required No special privileges are needed to use the utc help command. Examples dcecp> utc help add Adds a relative and absolute, or two relative, timestamps. compare Compares two timestamps to determine which is earlier. convert Converts a timestamp into the local timezone or GMT. multiply Multiplies a relative timestamp by a number. subtract Returns the difference between two timestamps. help Prints a summary of command-line options. operations Returns a list of the valid operations for this command. dcecp> utc multiply Multiplies a relative time (a length of time) by an integer or floating-point factor. The syntax is as follows: utc multiply rela- tive_timestamp {integer | floating_point_factor} The multiply operation accepts two arguments: a relative timestamp and an integer or floating-point factor. It multiplies the length of time (specified by the relative timestamp) by the integer or floating-point factor, returning the product as a relative timestamp. Privileges Required No special privileges are needed to use the utc multiply command. Examples dcecp> utc multiply +0-00:00:05.000I----- 3 +0-00:00:15.000I----- dcecp> utc operations Returns a list of the operations supported by the utc object. The syntax is as follows: utc operations The list of available operations is in alphabetical order except for help and operations, which are listed last. Privileges Required No special privileges are needed to use the utc operations command. Examples dcecp> utc operations add compare convert multiply subtract help operations dcecp> utc subtract Subtracts one timestamp from another, returning the difference as a relative timestamp. The syntax is as follows: utc subtract timestamp timestamp The subtract operation returns the difference between two timestamps that express either an absolute time and a relative time, two relative times, or two absolute times. Subtracting an absolute timestamp from a relative timestamp, however, is not allowed. The return value is an absolute or relative timestamp, depending on how the command is used. Privileges Required No special privileges are needed to use the utc subtract command. Examples dcecp> utc subtract 1994-10-18-13:22:32.816-00:00I----- +0-00:00:15.000I----- 1994-10-18-13:22:17.816+00:00I----- dcecp> RELATED INFORMATION
Commands: dcecp(1m), dcecp_clock(1m), dcecp_dts(1m), dtsd(1m). utc(1m)
All times are GMT -4. The time now is 04:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy