Get the date greater than defined date


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Get the date greater than defined date
# 1  
Old 01-24-2014
Get the date greater than defined date

Code:
 file.txt
2013-01-01
2013-01-02
2013-01-03
2013-01-04

I need some method to get only date which are greater than 2013-01-03 in a seperate file
Code:
2013-01-03
2013-01-04

Code:
I have tried  cat file.txt | awk -F. '$2 > '2013-01-03' {print $0}' >> a2.txt

# 2  
Old 01-24-2014
$2 is guaranteed to be blank for your input, since it has no second column.

awk does not need cat's help to read one file.

You cannot nest single quotes inside single quotes, use double-quotes inside the single-quotes.

Code:
awk '$1 > "2013-01-03"' inputfile >> outputfile

# 3  
Old 01-24-2014
Hello,

Could you please try the following. It will give dates grater then requested.
check_date is the input file.


Code:
while read line
do
if [[ "$line" > "2013-01-03" ]]
then
echo $line 
echo $line > OUTPUT_date_checking
fi
 
done < "check_date"


Thanks,
R. Singh

Last edited by RavinderSingh13; 01-24-2014 at 01:11 PM..
# 4  
Old 01-24-2014
Could this ?

Code:
$ cat <<test | awk 'function dform(t){gsub("-"," ",t);return mktime(t" "00" "00" "00)}dform($1)>=dform(inp)' inp="2013-01-03"     
2013-01-01
2013-01-02
2013-01-03
2013-01-04
test

2013-01-03
2013-01-04

for file
Code:
$ awk 'function dform(t){gsub("-"," ",t);return mktime(t" "00" "00" "00)}dform($1)>=dform(inp)' inp="2013-01-03"  file

# 5  
Old 01-24-2014
It will work but is severe overkill because YYYY-MM-DD dates sort alphabetically. This means you can compare them directly, just as strings, without converting them into epoch times.
# 6  
Old 01-24-2014
i used
Code:
 awk '$1 > "2013-01-03"' inputfile >> outputfile

but it is not taking 2013-01-03 i am getting only 2013-01-04 in my file
# 7  
Old 01-24-2014
Quote:
Originally Posted by ATWC
i used
Code:
 awk '$1 > "2013-01-03"' inputfile >> outputfile

but it is not taking 2013-01-03 i am getting only 2013-01-04 in my file


Try with :

Greater than or Equal >=
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date 19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. Shell Programming and Scripting

Find files greater than a particular date in filename.

I need a unix command which will find all the files greater that a particular date in the file name. say for example I have files like(filenaming cov : filename.YYDDMMSSSS.txt) abc.201206015423.txt abc.201207013456.txt abc.201202011234.txt abc.201201024321.txt efg.201202011234.txt... (11 Replies)
Discussion started by: lijjumathew
11 Replies

3. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

4. UNIX for Dummies Questions & Answers

List of Files which are Greater then a specific date

A newbie question... I need to get a list of the Files and folders which are greater then a specific date. I want write the output to a Text file. What I know ls -lrt gives me list of all the files ordered by date. Also ls > fileName will write the results to a text file. Please help (6 Replies)
Discussion started by: rkaif
6 Replies

5. Shell Programming and Scripting

Fetch contents of file greater than date

I have an input file which looks like something mentioned below: ====== 25/07/2011 05:06:59 : test ====== 25/07/2011 05:06:59 : test1 ====== 25/07/2011 05:08:09 : test2 ====== I need to write a script which will take date in the format "25/07/2011 05:07:01" as input and compare it... (1 Reply)
Discussion started by: bhallarandeep
1 Replies

6. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

7. Shell Programming and Scripting

Number of days between the current date and user defined date

I am trying to find out the number of days between the current date and user defined date. I took reference from here for the date2jd() function. Modified the function according to my requirement. But its not working properly. Original code from here is working fine. #!/bin/sh... (1 Reply)
Discussion started by: hiten.r.chauhan
1 Replies

8. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

9. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

10. Shell Programming and Scripting

Log File date compare for user defined range

:confused: Hi i am a noob and need a little help to finish my shell script. I am learning as i go but hit a problem. I am search thorugh logs(*.rv) files to find entires between two user defined dates, The script so far looks for the "START" and "END" of each entry at sees if it belongs To... (0 Replies)
Discussion started by: mojo24
0 Replies
Login or Register to Ask a Question