First off, straight comparisons of known correctly entered dates in the YYYYMMDD format can be treated as plain numbers for comparisons in shell using: -eq, -ne, -gt, -lt
Next the units for dates are days. To do further math like subtraction, you have to work on the number of days the date represents. Time and date in UNIX is epoch seconds.
So doing Julian dates in shell is somewhat tedious but is about the only way to proceed, i.e., convert a date to some kind epoch days. Epoch means the number of days since an arbitrary start date. For UNIX this is number of seconds since the first second in January 1, 1970. There are 86400 seconds per day. You can ignore leap seconds usually.
Chris (CFA) Johnson has a script in bash to do this. It is not beginner fodder.
Go here: Chris F.A. Johnson in Toronto, Ontario, Canada See if you can get a copy of the bash recipes book listed on this now-inactive site. Chris still posts here on UNIX Forums every once in a while.
[/code]
Last edited by jim mcnamara; 02-13-2018 at 07:53 PM..
RudiC, jim mcnamara, and I all made made several comments that should have helped you. It looks like you used one of my suggested and ignored everything else.
If you aren't interested in reading our comments, applying our suggestions, and answering our questions, there isn't much that we can do to help you.
This User Gave Thanks to Don Cragun For This Post:
Hi Community!
Following on from this code in another thread:
#!/bin/bash
file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'`
file_date=`/bin/date -d "$file_string"`
file_epoch=`/bin/date -d "$file_string" +%s`
now_epoch=`/bin/date +%s`
if
then
#let... (2 Replies)
I have two files to be compared to get the output of the differences.
File1 has a lot more lists than File2.
After searching a lot on this thread I'am unable to find the exact code that im willing to get.
This will be used as 'pre-check'/post-check utility (health check Tool) to compare... (1 Reply)
Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt .
I don't want to delete... (2 Replies)
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)
hi all,
How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt
how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Hi ALL,
I was looking out for any freeware tool which can compare config properties of 2 linux machines for ex java properties.
Tried in Google but no luck.
Any help would be greatly appreciated :) (3 Replies)
date --date='10:30am + 1 hour' +%H:%M
11:30 produces
date --date='10:30pm + 1 hour' +%H:%M produces
23:30
I want to do the following:
TIME="1:30pm"
date --date='$TIME + 1 hour' + %H:%M
to produce
14:30 (1 Reply)
Hi! I am trying to read a file and every line has a specific date as one of its fields.
I want to take that date and compare it to the date today plus 6 days.
while read line
do
date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD
if ; then
...proceed commands
... (1 Reply)
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... (4 Replies)
I am currently running the following Korn shell script which works fine:
#!/usr/bin/ksh
count=`db2 -x "select count(*) from schema.tablename"`
echo "count"
I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)