Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe string to GNU Date for conversion - how to make it read from stdin?

date -f tells it to do the same thing as -d except for every line in a file... you can set the filename to - to make it read from standard input.

echo "yesterday" | date +"%d %m %Y" -f -

Yes.

 echo "yesterday" | xargs date +"%d %m %Y" -d

You can use `command` or $(command) substitution:

date +"%d %m %Y" -d $(echo "yesterday")

Just to throw it in, in bash:

date +"%d %m %Y" -f <(echo yesterday)