HI,
I'm new in perl..
I'm not sure if that is easy to use Perl to change the timestamp
format in the text file..
I got the txt file from sybase database, because the format is
different , I need to change it suitable to out DB2 database..
I heard that Perl is good at text processing... But I'm not very
familiar with it...
For example I want to change the format from following
a|b|c|Jul 14 2000 4:56:00:000PM|d|e|f|Jul 14 2000
4:56:00:000PM|h|I|j
to
a|b|c|2000-07-14-16:56:00:000000|d|e|f|2000-07-14-16:56:00:000000|h|I|j
"|" is the seperator in the text, and the timestamp could be different
values and could happen at any place..
Is there any way to process the file easily?
Your help is very appreciated.. 6 4585
janet wrote: I want to change the format from following
a|b|c|Jul 14 2000 4:56:00:000PM|d|e|f|Jul 14 2000 4:56:00:000PM|h|I|j
to
a|b|c|2000-07-14-16:56:00:000000|d|e|f|2000-07-14-16:56:00:000000|h|I|j
"|" is the seperator in the text, and the timestamp could be different values and could happen at any place..
Is there any way to process the file easily?
There are a few ways. Assuming the whole file is in $text, this is one
approach:
my %months = (Jan => 1, Feb => 2, Mar => 3, Apr => 4,
May => 5, Jun => 6, Jul => 7, Aug => 8,
Sep => 9, Oct => 10, Nov => 11, Dec => 12);
$text =~ s{\|(\w{3})\s+(\d{1,2})\s+(\d{4})\s+
(\d{1,2})(:\d{2}:\d{2}:)(\d{3})(\w{2})\|}
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1},
$2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '|' }egx;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson wrote: { '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1}, $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '|' }egx;
Those lines are probably better replaced with:
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%03d', $3, $months{$1},
$2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '000|' }egx;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message news:<il********************@newsb.telia.net>... Gunnar Hjalmarsson wrote: { '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1}, $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '|' }egx;
Those lines are probably better replaced with:
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%03d', $3, $months{$1}, $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '000|' }egx;
HI,
I met a new problem when convert the data
For exp:
12:35:40, if converted, it would change to 24:45:40. that is not
correct. I'm not very familiar with Perl, who could help me how to do
it?
Gunnar, do you have time to take a look ?
janet wrote: Gunnar Hjalmarsson wrote: Gunnar Hjalmarsson wrote: { '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1}, $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '|' }egx; Those lines are probably better replaced with:
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%03d', $3, $months{$1}, $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '000|' }egx;
I met a new problem when convert the data
For exp:
12:35:40, if converted, it would change to 24:45:40. that is not correct. I'm not very familiar with Perl,
I know, you told us so in your original post. (I'm not very familiar
with the AM/PM time format.)
Since you asked for help here, I thought you were about to learn Perl,
so I hoped you would figure out how the the code I posted works, and
learn something new by doing so. Now I understand that that was never
your intention. Apparently you just wanted somebody to do your job for
you.
who could help me how to do it?
I won't.
Gunnar, do you have time to take a look ?
I'm not in the mood.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Try this:
if ($7 eq 'PM' && $4 == 12)
{
$hour = 0;
}
elsif ($7 eq 'PM')
{
$hour = 12+$4;
}
else
{
$hour = $4;
}
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1},
$2, $hour, $5, $6) . '|' }egx;
-HS Phuah
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message news:<xx********************@newsb.telia.net>... janet wrote: Gunnar Hjalmarsson wrote: Gunnar Hjalmarsson wrote:
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1}, $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '|' }egx;
Those lines are probably better replaced with:
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%03d', $3, $months{$1}, $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '000|' }egx;
I met a new problem when convert the data
For exp:
12:35:40, if converted, it would change to 24:45:40. that is not correct. I'm not very familiar with Perl,
I know, you told us so in your original post. (I'm not very familiar with the AM/PM time format.)
Since you asked for help here, I thought you were about to learn Perl, so I hoped you would figure out how the the code I posted works, and learn something new by doing so. Now I understand that that was never your intention. Apparently you just wanted somebody to do your job for you.
who could help me how to do it?
I won't.
Gunnar, do you have time to take a look ?
I'm not in the mood. hs*****@usa.com (Hon Seng Phuah) wrote in message news:<38*************************@posting.google.c om>... Try this:
if ($7 eq 'PM' && $4 == 12) { $hour = 0; } elsif ($7 eq 'PM') { $hour = 12+$4; } else { $hour = $4; }
{ '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1}, $2, $hour, $5, $6) . '|' }egx;
-HS Phuah
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message news:<xx********************@newsb.telia.net>... janet wrote: Gunnar Hjalmarsson wrote: > Gunnar Hjalmarsson wrote: >> >> { '|' . (sprintf '%d-%02d-%02d-%02d%s%06d', $3, $months{$1}, >> $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '|' }egx; > > Those lines are probably better replaced with: > > { '|' . (sprintf '%d-%02d-%02d-%02d%s%03d', $3, $months{$1}, > $2, $7 eq 'PM' ? 12+$4 : $4, $5, $6) . '000|' }egx;
I met a new problem when convert the data
For exp:
12:35:40, if converted, it would change to 24:45:40. that is not correct. I'm not very familiar with Perl,
I know, you told us so in your original post. (I'm not very familiar with the AM/PM time format.)
Since you asked for help here, I thought you were about to learn Perl, so I hoped you would figure out how the the code I posted works, and learn something new by doing so. Now I understand that that was never your intention. Apparently you just wanted somebody to do your job for you.
who could help me how to do it?
I won't.
Gunnar, do you have time to take a look ?
I'm not in the mood.
Hi, HS Phuah, Thanks very much...
Yes it is the problem I met in my work , ask for help on it.. I just
busy on sth.. had no time to learn in Perl in detail this couple
weeks...
I think here is another way another way to do it
$7 ='PM' && $4+12 < 24 : $4+12
Thanks everyone! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mike m |
last post by:
all,
was able to piece together the following php/html code. Basically I
want to push an SQL query and format it, present it to an html
document. The problem appears with the SQL query.
...
|
by: Bert Sierra |
last post by:
Hello --
I have what appears to be a simple PHP+MySQL query, but Dreamweaver
consistently generates PHP code which won't parse. I've stared at the
PHP code for several hours now, and I can't...
|
by: JS |
last post by:
I have a del file with timestamp format as: Jan 1 1995 12:00AM
I am trying to load this as:
modified by timestampformat "MMM/D/YYYY HH:MM TT"
but DB2 will not accept it. I have tried various...
|
by: Mike |
last post by:
I have an Access DB that I upsized to a SQL server DB. The tables that I
upsized I can't seem to modify. I wanted to insert some data into the table
and I am getting the following error:
...
|
by: klh |
last post by:
I am working with my developer group to switch from the type 2 to the
type 4 (Universal Driver).
Our set up is:
Host Data Base - DB2 z/os v7.1 (mainframe).
Client - DB2 Admin Client V8 FP8...
|
by: Ted |
last post by:
1) In several tables, in my MySQL version, I created columns using
something like the following:
`ab_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
This...
|
by: jim.clifford |
last post by:
Hello, I am experimenting with indexes and hope people can shed light
on some of my problems.
I am using SLQ 2000 on Win 2000 Server. Using the following query for
discussion;...
|
by: bdbeames |
last post by:
I never used Perl before, so I need a little help formating a date.
What I'm doing is querying a postgres database and then creating a .xml file for a RSS feed. I don't know how to correctly format...
|
by: Mark McIntyre |
last post by:
Hallvard B Furuseth wrote:
Setting aside that 4 is an entirely sensible tab width...
This seems to be the showstopper. Unless you now entirely own the code
yourself alone, don't reformat it...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |