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

// 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_news/js/av.js -
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/v3_tb/v.gif -
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/bp_88.gif - 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/11_19.gif - 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/store_digest -
FIRST_UP_PARENT/10.2.25.6 text/html

.....

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

···

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

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

* "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