Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Find the timestamp difference between two different colums in a file Post 302920611 by Corona688 on Friday 10th of October 2014 12:14:09 PM
Old 10-10-2014
Code:
$ cat timesub.awk

BEGIN {
        # Where time digits wrap.
        split("24 60 60", T);
        OFS="\t"
}
{
        # A[1]="00", A[2]="10", A[3]="10", etc.
        split($3, A, ":")
        split($4, B, ":")

        # Subtract group by group like longhand arithmetic.
        for(N=3; N>=1; N--)
        {
                B[N] -= A[N]
                M=N

                # If the count goes negative, borrow from the next digit, until we stop needing to borrow or run out of digits.
                while(M>0 && (B[M] < 0))
                {
                        B[M] += T[M]
                        B[M-1] --;
                        M--;
                }
        }

        NF=4    # Strip off extra columns
        # Add another column
        $(NF+1)=sprintf("%02d:%02d:%02d", B[1], B[2], B[3]);
} 1

$ awk -f timesub.awk data

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

$


Last edited by Corona688; 10-10-2014 at 01:25 PM..
These 2 Users Gave Thanks to Corona688 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
SHTOOL-PATH.TMP(1)					      GNU Portable Shell Tool						SHTOOL-PATH.TMP(1)

NAME
shtool-path - GNU shtool command dealing with shell path variables SYNOPSIS
shtool path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path path] str [str ...] DESCRIPTION
This command deals with shell $PATH variables. It can find a program through one or more filenames given by one or more str arguments. It prints the absolute filesystem path to the program displayed on "stdout" plus an exit code of 0 if it was really found. OPTIONS
The following command line options are available. -s, --suppress Supress output. Useful to only test whether a program exists with the help of the return code. -r, --reverse Transform a forward path to a subdirectory into a reverse path. -d, --dirname Output the directory name of str. -b, --basename Output the base name of str. -m, --magic Enable advanced magic search for ""perl"" and ""cpp"". -p, --path path Search in path. Default is to search in $PATH. EXAMPLE
# shell script awk=`shtool path -p "${PATH}:." gawk nawk awk` perl=`shtool path -m perl` cpp=`shtool path -m cpp` revpath=`shtool path -r path/to/subdir` HISTORY
The GNU shtool path command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 1998 for Apache. It was later taken over into GNU shtool. SEE ALSO
shtool(1), which(1). 18-Jul-2008 shtool 2.0.8 SHTOOL-PATH.TMP(1)
All times are GMT -4. The time now is 04:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy