Solved

date comarision script

Posted on 2002-07-04
5
235 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now