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
opendkim-genzone(8)					      System Manager's Manual					       opendkim-genzone(8)

NAME
opendkim-genzone - DKIM public key zone file generation tool SYNOPSIS
opendkim-genzone [-C address] [-d domain] [-D] [-E secs] [-N ns[,...]] [-o file] [-r secs] [-R secs] [-S] [-t secs] [-T secs] [-v] [-x conffile] [dataset] DESCRIPTION
opendkim-genzone generates a file suitable for use with named(8) to publish a set of public keys. The dataset parameter should specify a set of data as described in the opendkim(8) man page. It can currently refer to flat files, Sleepy- cat databases, comma-separated lists, LDAP directories or SQL databases. The dataset may be omitted if a configuration file (via the -x command line flag) is specified referring to a configuration file that sets a KeyTable parameter, in which case that value will be used. The database contents should be formatted as described for the KeyTable parameter, described in the opendkim.conf(5) man page. OPTIONS
-C contact Uses contact as the contact information to be used when an SOA record is generated (see -S below). If not specified, the userid of the executing user and the local hostname will be used; if the executing user can't be determined, "hostmaster" will be used. -d domain Restricts output to those records for which the domain field is the specified domain. -D Adds a "._domainkey" suffix to selector names in the zone file. -E secs When generating an SOA record (see -S below), use secs as the default record expiration time. The default is 604800. -N nslist Specifies a comma-separated list of nameservers, which will be output in NS records before the TXT records. The first nameserver in this list will also be used in the SOA record (if -S is also specified) as the authority hostname. -o file Sends output to the named file rather than standard output. -r secs When generating an SOA record (see -S below), use secs as the zone refresh time. The default is 10800. -R secs When generating an SOA record (see -S below), use secs as the zone retry time. The default is 1800. -S Asks for an SOA record to be generated at the top of the output. The content of this output can be controlled using the -E, -r, -R, -T options. The serial number will be generated based on the current time of day. -t ttl Puts a TTL (time-to-live) value of ttl on all records output. The units are in seconds. -T secs When generating an SOA record (see -S below), use secs as the default record TTL time. The default is 86400. -v Increases the verbosity of debugging output written to standard error. -x conffile Names an opendkim.conf(5) file to be read for LDAP-specific parameters when an LDAP dataset is given on the command line. Not required for other dataset types. The default is /etc/opendkim.conf. VERSION
This man page covers the version of opendkim-genzone that shipped with version 2.6.8 of OpenDKIM. COPYRIGHT
Copyright (c) 2010, 2012, The OpenDKIM Project. All rights reserved. SEE ALSO
opendkim(8), opendkim.conf(5) The OpenDKIM Project opendkim-genzone(8)
All times are GMT -4. The time now is 11:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy