dcronin135 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to translate the epoch time from a command output in AIX to human readable form. However, it does not seem to be picking up the replacement expression with the correct result rather it's reporting now. Any ideas ?

 lsuser -f username | perl -pe "print s/([0-9]{8,})/scalar localtime $1/e"

Replies are listed 'Best First'.
Re: lsuser epoch translate
by sn1987a (Curate) on Aug 15, 2014 at 17:54 UTC
    The key difference between your code and atcroft's code above is the quotes. With the double quotes in your example, the shell will replace the $1 before perl gets to see it. Using the single quotes will protect the variable names.
    $ echo "19284732 Test message 123456789012345" | perl -pe "s/(\d{8,})/ +scalar localtime $1/e;" Fri Aug 15 12:52:29 2014 Test message 123456789012345 $ echo "19284732 Test message 123456789012345" | perl -pe 's/(\d{8,})/ +scalar localtime $1/e;' Tue Aug 11 23:52:12 1970 Test message 123456789012345

      You are absolutely right! Don't know how I missed such a simple syntax.

Re: lsuser epoch translate
by atcroft (Abbot) on Aug 15, 2014 at 17:27 UTC

    I didn't have an AIX box to try the command on, so I mocked up some (what I thought reasonable) output, and was able to do what you are trying with this:

    echo "`date +%s` boxen foo Test message 123456789012345" | perl -pe 's/(\d{8,})/scalar localtime $1/e;'
    to get
    Fri Aug 15 12:23:47 2014 boxen foo Test message 123456789012345

    Hope that helps.