in reply to Need help in extracting timestamp from the line in a file
Change for to while while reading (<DATA>).. so you don't read all into memory at once#!/usr/bin/env perl use strict; use warnings; use Time::Piece; my @dates; while (<DATA>) { next unless /Launching the JVM with following options/; my ($date, $line) = split /::/,$_,2; $date = Time::Piece->strptime($date, "----- %a %b %d %T %Y"); push @dates, [ $date, $line ]; } for (@dates) { print $_->[0]->strftime("%Y-%m-%d %T") . " $_->[1]"; } __DATA__ ----- Sun Mar 8 10:51:20 2015::4426::Launching the JVM with following +options. # 2015-03-08 10:51:20 4426::Launching the JVM with following options.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Need help in extracting timestamp from the line in a file
by jayu_rao (Sexton) on Mar 10, 2015 at 05:10 UTC |