?
Solved

date comarision script

Posted on 2002-07-04
5
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

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