Command to pull date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command to pull date
# 1  
Old 08-17-2015
Command to pull date

I have one file with below entry. There are multiple entries, but for sample I used just three lines.
my requirment is to create a script by which it will pull only those entries which modification time is greater than 2 weeks (or 15 days). if I run script today, it will compare date from today and pull entriies which modification time is greater than 2 weeks.
Is there any command or combination of commands which can be used for this activity?

Input
Code:
Login = user1
Modification Time = July 27, 2015 4:57:55 AM EDT
Login = user2
Modification Time = June 24, 2015 5:39:23 AM EDT
Login = user3
Modification Time = Aug 5, 2015 4:53:53 AM EDT

Required Output
Code:
Login = user1
Modification Time = July 27, 2015 4:57:55 AM EDT
Login = user2
Modification Time = June 24, 2015 5:39:23 AM EDT

Below is Output of date command in my server
Code:
> date
Mon Aug 17 03:46:31 EDT 2015


Last edited by vbe; 08-17-2015 at 05:35 AM.. Reason: code tags please. not HTML...
# 2  
Old 08-17-2015
date command options/arguments vary depending version and OS
Of the OS and shell you use, you say nothing...
# 3  
Old 08-18-2015
Thanks for your reply ..!!

here are details

HTML Code:
$ uname -a
Linux ABC.com 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
HTML Code:
$ echo $0
-bash
# 4  
Old 08-18-2015
As date arithmetics are not that easily done, and my mawk doesn't support dates at all, I'll propose a shell script for you:
Code:
NOW=$(date +%s)
D15=$((86400*15))
while IFS="=" read A B; do [ "$A" == "Login " ] && LINE="$A=$B" || if ((NOW - $(date -d "$B" +%s) > D15)); then echo "$LINE"; echo "$A=$B"; fi; done <file3 
Login = user1
Modification Time = July 27, 2015 4:57:55 AM EDT
Login = user2
Modification Time = June 24, 2015 5:39:23 AM EDT

This User Gave Thanks to RudiC For This Post:
# 5  
Old 08-18-2015
Thanks Rudic ..!
I tested and script worked ... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

3. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

4. Shell Programming and Scripting

Need awk/sed command to pull out matching lines from a block

Hi, In order to make our debugging easier in log files, I need this script. My log file will be structured like this : ------Invoking myfile -param:start_time=1371150900000 -param:end_time=1371151800000 for 06/14/2013 <multiple lines here> ..... - Step Sybase CDR Table.0 ended... (3 Replies)
Discussion started by: Lakshmikumari
3 Replies

5. Shell Programming and Scripting

How to get tomorrow,yesterday date from date Command

Hi I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this. Regards Rajesh (5 Replies)
Discussion started by: rajeshmepco
5 Replies

6. Shell Programming and Scripting

Access log field - using awk to pull date/time

hey guys. the following line is a line taken from apache's access_log 10.10.10.10 - jdoe "GET /images/down.gif HTTP/1.1" 304 I'm concerned about the field that has the date and time in it. if assuming the delimiter in the file is a space, then the fourth field will always have the date... (5 Replies)
Discussion started by: SkySmart
5 Replies

7. UNIX for Dummies Questions & Answers

pull date from header and append to all records

I did some searches, but couldn't really find what I'm looking for. I have a file formatted as below: BOF ABC CO - XYZ COMM DATA OF 07/05/2011 EBA00000001 sdfa rtyus uyml EBB00000001 54682 984w3 EBA00000002 mkiyuasdf 98234 I want to pull the date from the header record and add it... (4 Replies)
Discussion started by: keeferb
4 Replies

8. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

9. UNIX for Dummies Questions & Answers

Need to pull Yesterdays Date...

I tried this and it works for the most part, but if the date is 20090301, it displays 20090300. YESTERDAY=$((`date +%Y%m%d` -1)) (2 Replies)
Discussion started by: cards0622
2 Replies

10. Shell Programming and Scripting

want to get previous date from date command in ksh

I want to get previous date from date command. I am using ksh shell. Exmp: today is 2008.09.04 I want the result : 2008.09.03 Please help. Thanks in advance. (4 Replies)
Discussion started by: rinku
4 Replies
Login or Register to Ask a Question