1828371 Members
2889 Online
109976 Solutions
New Discussion

perl help

 
SOLVED
Go to solution
Jeeshan
Honored Contributor

perl help

#!/usr/bin/perl -nl
BEGIN{
%m=(Jan=>1,Feb=>2,Mar=>3,Apr=>4,May=>5,Jun=>6,
Jul=>7,Aug=>8,Sep=>9,Oct=>10,Nov=>11,Dec=>12)};
m{^Event.+(\w{3})\s(\d\d).+\s(\d{4})} and
printf "%02d%02d%4d\n",$2,$m{$1},$3;
1;

For example:

# X="Event Time..........: Tue Mar 17 20:57:58 2009"
# echo ${X} | ./filter
17032009

works fine when the date is from 10 an onwards. but when the date was 1 to 9 then the script doesn't work. Please help.
a warrior never quits
3 REPLIES 3
Prashantj
Valued Contributor
Solution

Re: perl help

Hi Ahsan,

Please try to use below script.

#!/usr/bin/perl -nl
BEGIN{
%m=(Jan=>1,Feb=>2,Mar=>3,Apr=>4,May=>5,Jun=>6,
Jul=>7,Aug=>8,Sep=>9,Oct=>10,Nov=>11,Dec=>12)};
m{^Event.+(\w{3})\s(\d\d|\d).+\s(\d{4})} and
printf "%02d%02d%4d\n",$2,$m{$1},$3;
1;

Hope this will helpful.

Prashant/Vikas
Good judgment comes from experience and experience comes from bad judgment.
James R. Ferguson
Acclaimed Contributor

Re: perl help

Hi:

The requirement for a 2-digit day field or a space-filled 1-digit day could be met with this:

#!/usr/bin/perl -nl
BEGIN{
%m=(Jan=>1,Feb=>2,Mar=>3,Apr=>4,May=>5,Jun=>6,
Jul=>7,Aug=>8,Sep=>9,Oct=>10,Nov=>11,Dec=>12)};
m{^Event.+(\w{3})\s+(\d{1,2}).+\s(\d{4})} and
printf "%02d%02d%4d\n",$2,$m{$1},$3;
1;

The notation of "{1,2}" means at least one and no more than two. In this case, "\d{1,2}" signifies one or two digits.

Regards!

...JRF...
Jeeshan
Honored Contributor

Re: perl help

thnx
a warrior never quits