1

I've been trying to nut this out, but I'm stumped... I've tried to extrapolate the commands I found at How to replace epoch timestamps in a file with other formats?, but I'm can't get it yet.

My system has a command to read values from a database, one of the values I can read is in epoch time format:

[user@Dreadnaught config]# dbviewer -t Isagraf5.Resource._1.CompileDate
1488303650

If I manually copy the result to the date command, it works fine:

[user@Dreadnaught config]$ date -d@1488303650
Tue Feb 28 17:40:50 UTC 2017

I want to get this as a single command (so I can just add it to my alias list instead of having to load a sh script). I've tried all sorts of ways to pipe the result from the first command to the second, but I can't figure it out. What am I missing?

From the other referenced question, I've managed to join the result from the dbviwer query onto the date command, but not execute it.

[user@Dreadnaught config]$ dbviewer -t Isagraf5.Resource._1.CompileDate | sed 's/^//; s/\([0-9]\{10\}\)/date -d @\1/;s/$//'
date -d @1488303650
[user@Dreadnaught config]$ . dbviewer -t Isagraf5.Resource._1.CompileDate | sed 's/^//; s/\([0-9]\{10\}\)/date -d @\1/;s/$//'
-ash: /usr/bin/dbviewer: line 1: syntax error: unexpected "("

Thanks for your help...

1
alias dbdate='date -d@"$( dbviewer -t Isagraf5.Resource._1.CompileDate )"'

You should now be able to use dbdate as an alias for

date -d@"$( dbviewer -t Isagraf5.Resource._1.CompileDate )"

This command will run dbviewer -t Isagraf5.Resource._1.CompileDate and call date with its output inserted after the @.

$(...) is a command substitution. It will be substituted by the output of the command inside the $(...).

  • Brilliant, thanks! The combination of ' and " and substituting instead of piping is what I was missing. Works perfectly, thanks. – Scott Mar 1 '17 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.