Solved

date comarision script

Posted on 2002-07-04
5
237 Views
Last Modified: 2013-12-27
i have a file like this

usera date of birth 10-July-00
userb date of birth 08-Sep-01
userc date of birth 15-Apr-02
userd date of birth 03-Jan-00
---
--
-- etc


i want to know all the users whose date of birth is before jan-02.

how can i find.?


msnr
0
Comment
Question by:msnr
5 Comments
 
LVL 1

Accepted Solution

by:
billwcc earned 100 total points
ID: 7129999
Hey,

You need 2 things here:

1.  4-digit years in your data file.

2.  Perl!

Assuming your data file is called "data", and you have added 4-digit years, try this:

#!/usr/bin/perl
open(FILE, "./data") ||
   die ("Unable to open data file.\n");

while ($line = <FILE>){
   chop ($line);
      @fields = split(/-/, $line);
      if($fields[2] < 2002) {
         print "$line\n";
      }
}

You can modify the above to use 2-digit years, but the logic in the "if" clause becomes more complicated.
0
 
LVL 1

Author Comment

by:msnr
ID: 7131470
my idea is not only year....with month....

for ex..... before 2002 july...


0
 
LVL 1

Expert Comment

by:billwcc
ID: 7131821
Man, you really need to get Perl into your life!

There are any number of ways to go about this type of sorting problem.  You could set a lookup table where you map the months to a numeric value and then compare based on that, or just do a compound comparison based on the months as text.

0
 
LVL 20

Expert Comment

by:tfewster
ID: 8003355
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by billwcc
 
Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8065837
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question