?
Solved

date comarision script

Posted on 2002-07-04
5
Medium Priority
?
245 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 400 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 21

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

850 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