Solved

perl code

Posted on 2004-08-25
5
146 Views
Last Modified: 2010-03-05
hi..
i have this statment in the perl script that allows me to extract the date "02/31/04"
and insert it to the database in the form of "2004/02/31"
this is the statment :
  if( /Start Date\s*:\s*(\S+)/ ) {
    $job = $1;
    ($date = $2) =~ s!(\d\d)/(\d\d)/(\d\d)!20$3/$1/$2!;

however, the date formate given  is in this form "thur jul 22 10:10:18 2004"
how do i modify the above statment to extract onlt "jul 22 2004"

thanks.
0
Comment
Question by:TPoly
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 11899752
s/\w+\s+(\w+)\s+(\d+)\s+\d\d:\d\d:\d\d\s+(\d\d\d\d)/$1 $2 $3/;
0
 

Author Comment

by:TPoly
ID: 11899822
hi ozo,
 i tried the statement you have provided but it only extract "thur" and
insert it into the database.
0
 

Author Comment

by:TPoly
ID: 11899839
sorry..
my mistake i want to modify the above perl statement from
"thur jul 22 10:10:18 2004" to "2004/07/22"
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 11899893
$_="thur jul 22 10:10:18 2004";
@m{qw(jan feb mar apr may jun jul aug sep oct nov dec)}=('01'..'12');
 s!\w+\s+(\w+)\s+(\d+)\s+\d\d:\d\d:\d\d\s+(\d\d\d\d)!$3/$m{$1}/$2!;
print;
0
 

Author Comment

by:TPoly
ID: 11900059
hi ozo. the state ment work,
however it is unable to insert the date into the database and
also i have have duplicate dates but i have many text files
with different date.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

22 Experts available now in Live!

Get 1:1 Help Now