On Thu, Aug 09, 2001 at 10:32:07AM +0800, Marvin T. Pascual wrote:
>
> How could I compare integers (date) one-by-one from the format of
> 2000081015533160460708 to 08/10/2000 where the first 4 integers stands for
> the year (2000), the next 2 integers stands for the month (08 == August),
> and the next 2 integers stands for the day (10) so that we conclude that
> 2000081015533160460708 == 08/10/2000? Please ignore the integers after the
> day (15533160460708).
>
I'd just as soon use perl to do this kind of work. This type of work
is trivial in perl. If $line = '2000081015533160460708', then this
suffices:
$year = substr($line, 0, 4);
$month = substr($line, 4, 2);
$day = substr($line, 6, 2);
Or even more compactly and safely using regular expressions:
if ($line =~ /(\d{4,4})(\d{2,2})(\d{2,2})(\d*)/) {
$year = $1;
$month = $2;
$day = $3;
} else {
#input is not of the form we expect!
...
}
This also has the good effect of untainting $line, if your perl script
is running in taint check mode, making it safer against illegal input.
$4 also contains the extra digits after the date.
If you insist on using a shell script to do this you'll probably have
to use crufty sequences of awk, sed, and grep to do it, and wind up
obfuscating the problem even more. Since you don't really know how to
do shell script programming that much (as you're asking this question
in the first place), I would strongly suggest you attempt to beef up
perl programming skill instead. Shell scripts have their place, but
the problem you're describing is too complicated to be easily
programmed in the shell. Use the right tools for the right job.
Have a look at some of my (still incomplete) course slides on Perl at
http://203.176.75.250/resources.html (the domain name I got from Boss
Migs for this machine evaporated when we recently fixed the DNS
records here at Inter.Net *sigh*) if you want a brief introduction and
tutorial for programming Perl.
--
Rafael R. Sevilla <[EMAIL PROTECTED]> +63(2) 8177746 ext. 8311
Programmer, InterdotNet Philippines +63(917) 4458925
http://dido.engr.internet.org.ph/ OpenPGP Key ID: 0x5CDA17D8
PGP signature