perl replace awk strftime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl replace awk strftime
# 1  
Old 06-08-2010
perl replace awk strftime

Hi Everyone
i have a perl file below, one of the line is convert the pcho time to human readable format.

Code:
$value=`awk 'BEGIN{print strftime("%c",1273236600)}' | tr -d '\n'`;

if image, if i have lots of pcho time value in a file, if i use this awk, strftime, then tr -d to remove the \n, then assign it to the variable, this process is very slow.

any way to improve it? like perl has built in function, instead of `` the awk.

Thanks
# 2  
Old 06-09-2010
Quote:
Originally Posted by jimmy_y
Hi Everyone
i have a perl file below, one of the line is convert the pcho time to human readable format.

Code:
$value=`awk 'BEGIN{print strftime("%c",1273236600)}' | tr -d '\n'`;

if image, if i have lots of pcho time value in a file, if i use this awk, strftime, then tr -d to remove the \n, then assign it to the variable, this process is very slow.

any way to improve it? like perl has built in function, instead of `` the awk.

...
If you are looking for the equivalent of this -

Code:
awk 'BEGIN{print strftime("%c",1273236600)}'

in Perl, then you may want to use the "POSIX" module, which includes the strftime function -

Code:
perl -MPOSIX -le 'print POSIX::strftime("%c", localtime 1273236600)'

The POSIX module is part of Perl's standard distribution, atleast on *nix systems. Otherwise CPAN is your one-stop shop.

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 3  
Old 06-09-2010
for awk, use printf, instead of awk|tr, for my file with 35k lines, it saves me around 12 seconds. Smilie

use POSIX instead of awk, it saves me around 2 mins and 30 secs (2.30mins) Smilie Smilie Smilie Smilie Smilie

so you can image, each line in that file, has many many time conversation, plus lots lots lines, it really saves lots of time.

Thank tyler SmilieSmilie

Last edited by jimmy_y; 06-09-2010 at 02:02 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace my perl with awk or sed

My code below will print only the email address from all lines. I want to convert it with sed or awk.. also what if i just want to find only filenames. cat LIS_EMAIL | perl -wne'while(/+@+\w+/g){print "$&\n"}' Hoping to extract the filename such us .exe, .bin. From file that has scrambled... (8 Replies)
Discussion started by: invinzin21
8 Replies

2. Shell Programming and Scripting

Combining awk printf and print strftime command

I have a lines like below, captured from rrdtool fetch command, 1395295200 2.0629986254e+06 7.4634784967e+05 1395297000 2.0198121616e+06 6.8658888903e+05 1395298800 1.8787141122e+06 6.7482866452e+05 1395300600 1.7586118678e+06 6.7867977653e+05 1395302400 1.8222762151e+06 7.1301678859e+05I'm... (3 Replies)
Discussion started by: rk4k
3 Replies

3. Shell Programming and Scripting

awk mktime(strftime(format,"6-FEB-2013 08:50:03.841")

I'm trying to use AWK to filter on some dates in a field by converting them to Unix Time. mktime(strftime(format,"6-FEB-2013 08:50:03.841")What is the proper format for my date strings as they appear in my database? My first thought is %d-%b-%Y %H:%M:%Sbut I see the following issues: %d is... (3 Replies)
Discussion started by: Michael Stora
3 Replies

4. Shell Programming and Scripting

Help on awk strftime

cat file 41285.000034722223 41285.000567129631 41285.000069444446 41285.001122685186 41285.000092592592 41285.001620370371 41285.000138888892 41285.00340277778 41285.000185185185 41285.000405092593 41285.000196759262 41285.000856481478 41285.000208333331 41285.000717592593... (5 Replies)
Discussion started by: phpshell
5 Replies

5. Shell Programming and Scripting

Sed/awk/perl command to replace pattern in multiple lines

Hi I know sed and awk has options to give range of line numbers, but I need to replace pattern in specific lines Something like sed -e '1s,14s,26s/pattern/new pattern/' file name Can somebody help me in this.... I am fine with see/awk/perl Thank you in advance (9 Replies)
Discussion started by: dani777
9 Replies

6. Shell Programming and Scripting

replace awk with a perl one liner (REGEXP and FS)

hello, I want to replace awk with a perl one liner in unix. i use in awk REGEX and FS ( field separator) because awk syntaxes in different unix os versions have not the same behaviour. Awk, Nawk and GNU Awk Cheat Sheet - good coders code, great reuse i have a file named "file" and want... (5 Replies)
Discussion started by: bora99
5 Replies

7. Programming

strftime equivalent in c++

HI, i wish to convert a millsec value to a readable string format. the one option is to use strftime. However this is a bit costly (1-5 micros). is there a a faster way to do so with just string manipulation (Note i have the date object which has the time details but wish o avoid strftime) (2 Replies)
Discussion started by: wojtyla
2 Replies

8. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

9. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

10. Shell Programming and Scripting

gawk and strftime()

Strange behaviour of the strftime() function from gawk (3.1.5): $ awk 'BEGIN{print strftime("%T", 3600)}' > 02:00:00 $ awk 'BEGIN{print strftime("%T", 0)}' > 01:00:00 Obviously something with DST but I can not figure out why? To me 3600 epoch seconds remains 01:00, DST or not. From... (2 Replies)
Discussion started by: ripat
2 Replies
Login or Register to Ask a Question