Sponsored Content
Top Forums Shell Programming and Scripting ksh compare dates INSIDE a file (ie date A is > date B) Post 302561849 by right_coaster on Wednesday 5th of October 2011 11:16:02 AM
Old 10-05-2011
ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line.

I thought I would need to change the dates/times to epoch seconds but I can't figure out how to do update every date/time in the files to epoch. I'm not even sure if this would be the best way. Below is a snip from the joined files:

Code:
 
AO          | SYS.IO.LIB    | 2011-09-20 11:35:15     AO          | SYS.IO.LIB    | 2011-09-20 11:35:15
AR          | SYS.IO.LIB    | 2011-09-21 12:02:16     AR          | SYS.IO.LIB    | 2011-09-21 12:02:16
AT          | SYS.IO.LIB    | 2011-09-24 17:30:17     AT          | SYS.IO.LIB    | 2011-09-22 19:30:17
AW          | SYS.IO.LIB    | 2011-09-22 11:14:19     AW          | SYS.IO.LIB    | 2011-09-20 11:35:19
AZ          | SYS.IO.LIB    | 2011-09-20 11:35:20     AZ          | SYS.IO.LIB    | 2011-09-20 11:35:20
BB          | SYS.IO.LIB    | 2011-09-20 11:35:24     BB          | SYS.IO.LIB    | 2011-09-20 11:35:24
BC          | SYS.IO.LIB    | 2011-09-28 05:58:26     BC          | SYS.IO.LIB    | 2011-09-20 11:35:26
BI          | SYS.IO.LIB    | 2011-09-30 21:20:27     BI          | SYS.IO.LIB    | 2011-09-20 11:35:27
BR          | SYS.IO.LIB    | 2011-09-11 02:10:29     BR          | SYS.IO.LIB    | 2011-09-20 11:35:29
BS          | SYS.IO.LIB    | 2011-09-20 11:35:30     BS          | SYS.IO.LIB    | 2011-09-20 11:35:30
CB          | SYS.IO.LIB    | 2011-09-13 10:48:32     CB          | SYS.IO.LIB    | 2011-09-20 11:35:32
CD          | SYS.IO.LIB    | 2011-09-20 11:35:36     CD          | SYS.IO.LIB    | 2011-09-20 11:35:36
CD080ID9    | SYS.IO.LIB    | 2011-09-01 23:00:38     CD080ID9    | SYS.IO.LIB    | 2011-09-20 11:35:38
CD082ID9    | SYS.IO.LIB    | 2011-09-20 11:35:40     CD082ID9    | SYS.IO.LIB    | 2011-09-20 11:35:40
CG          | SYS.IO.LIB    | 2011-09-20 11:35:44     CG          | SYS.IO.LIB    | 2011-09-20 11:35:44
CI          | SYS.IO.LIB    | 2011-09-20 11:35:45     CI          | SYS.IO.LIB    | 2011-09-20 11:35:45

Any assistance is greatly appreciated.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

compare today's date with date in a file

Hi I am very new to scripting, Can someone show me how to (in unix shell script) compare the system's date with a date in a file. The requirement is to somehow open this file (which will only have a date in it) and compare it with today's date. If they are equal execute a procedure below but if... (4 Replies)
Discussion started by: siog
4 Replies

2. Shell Programming and Scripting

Compare dates in a field and print the latest date row

Hi, I need a shell script which should find the latest date in the field of file and print that line only. For eg., I have a file /date.log Name Date Status IBM 06/06/07 close DELL 07/27/07 open DELL 06/07/07 open : : : From... (1 Reply)
Discussion started by: cvkishore
1 Replies

3. Shell Programming and Scripting

change date format and then compare dates

I have filenames filenameA_fg_MMDDYY.tar.gz filenameASPQ_fg_MMDDYY.tar.gz filenameAFTOPHYYINGH_fg_MMDDYY.tar.gz filenameAGHYSW_fg_MMDDYY.tar.gz My requiremnt needs to extract date which is in MMDDYYand change it into YYYYMMDD format. I have done the following: filedate=`echo... (5 Replies)
Discussion started by: RubinPat
5 Replies

4. Shell Programming and Scripting

Generate quarter dates with begin date and end date

Hi All, I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user: begin_date = "2009-01-01" end_date = 2010-04-30" required output: 2009-01-01 2009-03-31 09Q01 2009-04-01 2009-06-30 09Q02 . . till 2010-01-01 2010-03-31 10Q01 ... (9 Replies)
Discussion started by: sol_nov
9 Replies

5. UNIX and Linux Applications

sqlite: calculating with dates - compare current date minus 6 months with stored record

Hi I have a table with name, date in format DD.MM.YYYY. I need to something like this (I try to explain in pseudo code) if SYSDATE (current date) minus 6 months > $expiry date print OK else print NOK with $name and $expiry date I know this is possible with Oracle. How to do this... (0 Replies)
Discussion started by: slashdotweenie
0 Replies

6. Shell Programming and Scripting

Need to capture all dates between start date and End date.

Hi All, I enter Start date and end date as parameters. I need to capture dates between start date and end date. Please let me know if you have any idea the same. Thanks in advance. Nagaraja Akkivalli. (5 Replies)
Discussion started by: Nagaraja Akkiva
5 Replies

7. Shell Programming and Scripting

compare date and time inside data of two files

i have two files with identical no of columns. 6th columns is date (MM/DD/YY format) and 7th columns is time (HH:MM:SS) format. I need to compare these two vaules and if the date & time is higher than fileA, save it on fileC; if the value is lower, then save it on fileD CONDITIONS... (7 Replies)
Discussion started by: ajiwww
7 Replies

8. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

9. Shell Programming and Scripting

Searching for unknown date inside the file and replace to new date

Hello, Iam a newbies to Shell scripting. Iam trying to replace the date inside the file to new date. is there anyway that we can just use the pattern to search as "..." I have many files want to replace with the same date, and each file contains different date. Thanks for your help. ... (2 Replies)
Discussion started by: Daro
2 Replies

10. Shell Programming and Scripting

Compare the system date with date from a text file

I get the date that's inside a text file and assigned it to a variable. When I grep the date from the file, I get this, Not After : Jul 28 14:09:57 2017 GMT So I only crop out the date, with this command echo $dateFile | cut -d ':' -f 2,4The result would be Jul 28 14:57 2017 GMT How do I... (3 Replies)
Discussion started by: Loc
3 Replies
NetSDS::Util::DateTime(3pm)				User Contributed Perl Documentation			       NetSDS::Util::DateTime(3pm)

NAME
NetSDS::Util::DateTime - common date/time processing routines SYNOPSIS
use NetSDS::Util::DateTime; print "Current date: " . date_now(); DESCRIPTION
This package provides set of routines for date and time processing. EXPORTED FUNCTIONS
date_now_array([TIME]) Returns array of date items for given date. If source date is not set current date used. date_now([TIME]) Return [given] date as string. 2001-12-23 14:39:53 date_now_iso8601([TIME]) Return date as ISO 8601 string. 20011223T14:39:53Z <http://en.wikipedia.org/wiki/ISO_8601> http://www.w3.org/TR/NOTE-datetime <http://www.w3.org/TR/NOTE-datetime> date_strip(DATE) Trim miliseconds from date. date_date(DATE) Trim time part from date. date_time(DATE) Trim date part from date. time_from_string($string) Return parsed date/time structure. date_from_string($string) Return date from string representation. date_inc([INCREMENT, [TIME]]) Return date incremented with given number of seconds. date_inc_string([INCREMENT, [TIME]]) Return string representation of date incremented with given number of seconds. EXAMPLES
None yet BUGS
Unknown yet SEE ALSO
Date::Parse, Date::Format TODO
Import stuff from Wono project AUTHOR
Valentyn Solomko <val@pere.org.ua> Michael Bochkaryov <misha@rattler.kiev.ua> perl v5.12.4 2011-08-27 NetSDS::Util::DateTime(3pm)
All times are GMT -4. The time now is 07:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy