[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: equivalent idiom for ruby " perl -pe 's/(\d+)/localtime($1)/e '"

Peña, Botp

3/21/2005 7:09:00 AM

Jim Freeze [mailto:jim@freeze.org] wrote:

// ruby -pe '$_.gsub!(/(\d+)/, Time.local("\\1".to_i).to_s)'
///var..access.log

Jim, thanks for that quick tip. It has some slight drawbacks though. I get
all January 1sts.

eg.

proxy:~ # ruby -pe '$_.gsub!(/^(\d+)/, Time.local "\\1".to_i).to_s)'
/var/log/squid/access.log

Sat Jan 01 00:00:00 PHT 2000.014 1277 10.3.25.5 TCP_REFRESH_HIT/304 339
GET http://newsimg.bbc.co.uk/nol/ifs_new... -
FIRST_UP_PARENT/10.2.25.6 application/x-javascript
Sat Jan 01 00:00:00 PHT 2000.337 322 10.3.25.5 TCP_REFRESH_HIT/304 323
GET http://newsimg.bbc.co.uk/shared/img/v... -
FIRST_UP_PARENT/10.2.25.6 image/gif


Jason Sweat [mailto:jason.sweat@gmail.com] wrt:

// ruby -pe '$_.gsub!(/^(\d+)/, Time.at($1.to_i).to_s)'

Thanks Jason. i removed the $_ to make it neater. But it has some drawbacks
still. Seems that the date/time gets fixed at January for the first record
and then fixed at the start date thereafter..... In other words, the
date/time doesn't change...

eg.
proxy:~ # ruby -pe 'gsub!(/^(\d+)/, Time.at($1.to_i).to_s)'
/var/log/squid/access.log
Thu Jan 01 08:00:00 PHT 1970.838 12 10.3.25.5 TCP_IMS_HIT/304 251 GET
http://images.dailyinbox.com/images... - NONE/- image/gif
Mon Mar 21 04:16:55 PHT 2005.848 8 10.3.25.5 TCP_IMS_HIT/304 251 GET
http://images.dailyinbox.com/images... - NONE/- image/gif
Mon Mar 21 04:16:55 PHT 2005.856 5 10.2.25.6 TCP_DENIED/401 1818 GET
http://bugoproxy:3128/squid-internal-periodic/store_digest - NONE/-
text/html
Mon Mar 21 04:16:55 PHT 2005.858 18 10.3.25.5 TCP_MISS/401 1902 GET
http://10.2.25.5:3128/squid-internal-periodic/st... -
FIRST_UP_PARENT/10.2.25.6 text/html

.....

Mon Mar 21 04:16:55 PHT 2005.856 ... all the rest..


James Edward Gray II [mailto:james@grayproductions.net] wrote:

// ruby -pe 'gsub!(/\d+/) { |t| Time.at(t.to_i) }' /var/log/squid/access.log

James, you thought it right. Thanks. It's the shortest so far and no $_ and
$1 there! And the block form gives me emphasis on what to concentrate on.
Cool -and it simply works!

Thanks for the great tip.

-botp




1 Answer

Jim Freeze

3/21/2005 12:41:00 PM

0

* "Peña, Botp" <botp@delmonte-phil.com> [2005-03-21 16:08:41 +0900]:

> Jim Freeze [mailto:jim@freeze.org] wrote:
>
> // ruby -pe '$_.gsub!(/(\d+)/, Time.local("\\1".to_i).to_s)'
> ///var..access.log
>
> Jim, thanks for that quick tip. It has some slight drawbacks though. I get
> all January 1sts.

Oops. I should have submitted the block version of gsub.

--
Jim Freeze
Code Red. Code Ruby