Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Find the timestamp difference between two different colums in a file Post 302920891 by rpm120 on Monday 13th of October 2014 10:44:36 AM
Old 10-13-2014
Quote:
Originally Posted by Akshay Hegde
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

 

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
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 08:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy