Compare two date columns in same file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two date columns in same file
# 1  
Old 03-07-2014
Compare two date columns in same file

Hi All,

Need to compare two date columns from the filname FinalDate.txt. My data's are like below

HTML Code:
 1/3/2012   1/3/2012   5000    
 6/21/2011  6/25/2011  6000
 2/28/2011  2/28/2011  7000
 7/16/2010  8/16/2010  8000  
 7/14/2010  10/26/2010 9000
 2/13/2012  2/13/2012  10000
 8/22/2011  10/12/2011  11000
 1/18/2012  5/28/2012  12000
 Expected Output:

If D_EXP_STR column is date greater than D_OT_START date column then I need to print the Amount column as output.

Kindly help me how can I achieve this result.
# 2  
Old 03-07-2014
I couldn't exactly understand your question.
if you want to print amount if D_EXP_STR > D_OT_START then, you will get the below output

Anyways, if this is your requirement, below is the code
awk 'NR > 1 {split($1, a, "/"); split($2, b, "/"); ex = (b[3] b[1] b[2]); ot = (a[3] a[1] a[2]); if((ot/1000) < (ex/1000)) {print $3}}' FinalDate.txt

awk '{split($1, a, "/"); split($2, b, "/"); if((b[3] b[1] b[2])/1000 > (a[3] a[1] a[2])/1000) print $3}' FinalDate.txt

Last edited by SriniShoo; 03-07-2014 at 04:37 AM.. Reason: alternate
# 3  
Old 03-07-2014
Thanks Srini for your reply. I will check tomorrow and update the statusSmilie
# 4  
Old 03-07-2014
Another one...
while read date1 date2 data
   [[ $date1 =~ ^D ]] && continue
   [[ $(date +%s -d $date2) -gt $(date +%s -d $date1) ]] && echo $data
done < infile


Last edited by ahamed101; 03-07-2014 at 04:09 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk: compare values in two columns of the same file

I'm trying to learn awk, but I've hit a roadblock with this problem. I have a hierarchy stored in a file with 3 columns: id name parentID 4 D 2 2 B 1 3 C 1 1 A 5 I need to check if there are any values in column 3 that are not represented anywhere in column 1. I've tried this: awk '{arr;}... (7 Replies)
Discussion started by: kaktus
7 Replies

2. 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

3. Shell Programming and Scripting

Compare columns in a single file

i have the following files (all separated by tabs): file 1.txt 1 yes 2 no 3 yes 4 yes file 2.txt a no b no c yes d no i combine the above files in file 3 which looks like file 3.txt 1 yes a no 2 no b no 3 yes c yes 4 yes d no now, i need to compare the values between column 2... (3 Replies)
Discussion started by: msonoth
3 Replies

4. Shell Programming and Scripting

Compare Multiple Columns in one file

Hello guys, I am quite new to Shell Scripting and I need help for this I have a CSV file like this: Requisition,Order,RequisitionLineNumber,OrderLineNumber REQ1,Order1,1,1 REQ1,Order1,1,3 REQ2,Order2,1,5 Basically what I want to do is compare the first 3 fields If all 3 fields are the same... (5 Replies)
Discussion started by: jeffreybsu
5 Replies

5. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: right_coaster
4 Replies

6. Shell Programming and Scripting

script to compare two columns in a file

Dear everyone, I need any sort of shell script or perl script would do the following. I have a txt file as follows: ;Stretnumber Resident Resdient (not in file) 16 John Mary 16 Mary Parker 16 Nancy Smith 16 Mary John 18 Trey ... (5 Replies)
Discussion started by: sasharma
5 Replies

7. UNIX for Dummies Questions & Answers

To compare first two columns in an excel file

Hi All, i have a excel sheet with two columns as below. column1 column2 100 100 200 300 300 400 400 400 500 600 i need to compare the values these two columns and the output should be printed in the third column...if these values are equal the output should be green and if these... (2 Replies)
Discussion started by: arunmanas
2 Replies

8. Shell Programming and Scripting

compare file columns

I need help in file comparision. I have two files in below format: FILE_A: ------- COL1 COL2 COL3 COL4 COL5 FILE_B: ------- COL1A COL1B COL1C COL1D COL1E i want to compare for a for each row in FILE_A and FILE_B COL1 of FILE_A with COL1B of FILE_B COL3 of FILE_A with COL1E of... (1 Reply)
Discussion started by: learnoutmore99
1 Replies

9. UNIX for Dummies Questions & Answers

compare date with date in file

Hello everyone, I'm in desperate need of your help for this challenge I have below: The run_dt_tbl has only 1 column and 1 row that contains a particular date in format mmddyy. I want to some how compare today's date with the date in this table that will be preset by someone else. If the dates... (2 Replies)
Discussion started by: siog
2 Replies

10. 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
Login or Register to Ask a Question