Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Find the timestamp difference between two different colums in a file Post 302920616 by Akshay Hegde on Friday 10th of October 2014 01:02:59 PM
Old 10-10-2014
Input
Code:
akshay@nio:/tmp$ cat file
2014/10/09    CDE876172588765        00:09:45    00:10:10    200    200    11.7093
2014/10/09    CDE366134588757        01:04:34    01:04:54    210    210    9.8898
2014/10/09    CDE765172345745        03:05:46    03:06:01    100    100    10.0601
2014/10/09    CDE896983529766        08:01:12    08:01:49    120    120    13.2231
2014/10/09    CDE123422323765        11:23:23    11:24:02    110    110    11.2226
2014/10/09    CDE098672481122        16:45:22    16:45:57    290    290    12.7123
2014/10/09    CDE886488758909        19:56:41    19:57:04    100    100    12.7693
2014/10/09    CDE398075446784        23:07:11    23:07:51    170    170    6.9857

Command
Code:
awk 'function dfor(time, a){ split(time, a, /:/); return 3600*a[1] + 60*a[2] + a[3] }{print $1,$2,$3,$4,dfor($4)-dfor($3)" secs"}' OFS='\t' file

Same in Perl if interested

Code:
perl -wlape 'sub dfor{@x=split(":",shift);return $x[0]*3600+$x[1]*60+$x[2]} $F[4] = dfor($F[3])-dfor($F[2])." secs"; $_ = join("\t",@F[0 .. 4]) ' file


Output

Code:
2014/10/09	CDE876172588765	00:09:45	00:10:10	25 secs
2014/10/09	CDE366134588757	01:04:34	01:04:54	20 secs
2014/10/09	CDE765172345745	03:05:46	03:06:01	15 secs
2014/10/09	CDE896983529766	08:01:12	08:01:49	37 secs
2014/10/09	CDE123422323765	11:23:23	11:24:02	39 secs
2014/10/09	CDE098672481122	16:45:22	16:45:57	35 secs
2014/10/09	CDE886488758909	19:56:41	19:57:04	23 secs
2014/10/09	CDE398075446784	23:07:11	23:07:51	40 secs

These 2 Users Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Shell] How make colums in text file ??

hi, i have little pb, i would like make a colums, but my server not recongize "\t" or i write wrong.... and iam little noobs and no know awk... #!/bin/ksh #---------------------------------------------------------------------------- # Fichiers : ctrl.sh et ctrl2005.txt ... (6 Replies)
Discussion started by: parola
6 Replies

2. AIX

Unix shell scripting to find latest file having timestamp embedded...

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (2 Replies)
Discussion started by: kaushik25
2 Replies

3. UNIX for Advanced & Expert Users

RCS - Find difference between 2 different versions of a file

Hi, I have a c file in my repository. We are using RCS(Revision Control System) to control and manage the versions. I need to find 1. Difference between the current version with a different version 2. Difference between any two different versions of a file. Ex Difference between 1.14 and... (1 Reply)
Discussion started by: kelangovan
1 Replies

4. Shell Programming and Scripting

find difference in file column...

Hi All, i have a file that is tab delimited. i need help to find the rows which are having same price based on the site code but some times, there are difference so i need to find only the records which are different in all site code. Dept Sec Barcode 10001 10002 10003 10004... (1 Reply)
Discussion started by: malcomex999
1 Replies

5. Shell Programming and Scripting

Find file size difference in two files using awk

Hi, Could anyone help me to solve this problem? I have two files "f1" and "f2" having 2 fields in each, a) file size and b) file name. The data are almost same in both the files except for few and new additional lines. Now, I have to find out and print the output as, the difference in the... (3 Replies)
Discussion started by: royalibrahim
3 Replies

6. Shell Programming and Scripting

Rearranging the colums in a tab delimited file

I want to rearrange some of my columns in my dat file; how do i do this using a script Suppose, I have an input file like this: BASENAME STREETTYPE PREFIX SUFFIX HOUSENUMBER BUILDUP ORDER8 ORDER2 ORDER1 ISOCOUNTRYCODE POSTALCODE SILVER LAKE RD NW 1135 NEW BRIGHTON RAMSEY MINNESOTA USA 55112... (4 Replies)
Discussion started by: ramky79
4 Replies

7. Shell Programming and Scripting

Check/Parse log file's lines using time difference/timestamp

I was looking at this script which outputs the two lines which differs less than one sec. #!/usr/bin/perl -w use strict; use warnings; use Time::Local; use constant SEC_MILIC => 1000; my $file='infile'; ## Open for reading argument file. open my $fh, "<", $file or die "Cannot... (1 Reply)
Discussion started by: cele_82
1 Replies

8. Shell Programming and Scripting

Reading colums from a text file

Hi all, I have a text file that has (4) columns. There are about 300 lines on this file. It is a plain text file. I am looking to write a simple script that will read each line from the file and generate another text file. The file looks something like this: These are the columns: ... (4 Replies)
Discussion started by: adamw
4 Replies

9. UNIX for Beginners Questions & Answers

UNIX utility to find difference in folder, file and contents of file against a base version

Hi, I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility? Thanks,... (6 Replies)
Discussion started by: Sripathi_ks
6 Replies

10. UNIX for Beginners Questions & Answers

awk code to find difference in second file which is not present in first file .

Hi All, I want to find difference between two files and output only lines which are not present in second file .I am using awk and I am getting only the first difference but I want to get all the lines which are not present in file2 .Below is the code I am using . Please help to get the desired... (7 Replies)
Discussion started by: srinivasrao
7 Replies
ntp-wait(1)							   User Commands						       ntp-wait(1)

NAME
ntp-wait - Wait for ntpd to stabilize the system clock SYNOPSIS
ntp-wait [-flags] [-flag [value]] [--option-name[[=| ]value]] All arguments must be options. DESCRIPTION
ntp-wait will send at most num-tries queries to ntpd(8), sleeping for secs-between-tries after each status return that says ntpd(8) has not yet produced a synchronized and stable system clock. ntp-wait will do this quietly, unless the -v flag is provided. This can be useful at boot time, to delay the boot sequence until after ntpd -g has set the time. OPTIONS
-n number, --tries=number Number of times to check ntpd. This option takes an integer number as its argument. The default number for this option is: 100 The maximum number of times we will check ntpd to see if it has been able to synchronize and stabilize the system clock. -s secs-between-tries, --sleep=secs-between-tries How long to sleep between tries. This option takes an integer number as its argument. The default secs-between-tries for this option is: 6 We will sleep for secs-between-tries after each query of ntpd that returns "the time is not yet stable". -v, --verbose Be verbose. By default, ntp-wait is silent. With this option, ntp-wait will provide status information. -?, --help Display usage information and exit. -!, --more-help Pass the extended usage information through a pager. -v [{v|c|n --version [{v|c|n}]}] Output version of program and exit. The default mode is `v', a simple version. The `c' mode will print copyright information and `n' will print the full copyright notice. EXIT STATUS
One of the following exit values will be returned: 0 (EXIT_SUCCESS) Successful program execution. 1 (EXIT_FAILURE) The operation failed or the command syntax was not valid. 70 (EX_SOFTWARE) libopts had an internal operational error. Please report it to autogen-users@lists.sourceforge.net. Thank you. AUTHORS
Harlan Stenn NOTES
This document corresponds to version 4.2.8p13 of NTP. This manual page was AutoGen-erated from the ntp-wait option definitions. ntp (4.2.8p13) 20 Feb 2019 ntp-wait(1)
All times are GMT -4. The time now is 02:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy