3 ms·
Dagnabbit I overslept! I use BitBar on my macbook to display the epoch second on my menu bar in a format like this: { 1,600,003,345 } The script to do that is
by bloopernova 6y ago
Dagnabbit I overslept!
I use BitBar on my macbook to display the epoch second on my menu bar in a format like this: { 1,600,003,345 }
The script to do that is:
EPOCH=$(/bin/date +%s | /usr/local/bin/sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')
echo "{" "${EPOCH}" "}"
Separating the epoch into thousands was done with the help of this Stackoverflow question: https://unix.stackexchange.com/questions/113795/add-thousands-separator-in-a-number https://unix.stackexchange.com/questions/113795/add-thousand...
EDIT: This is a much simpler way of writing it, thanks to GNU Coreutils' "numfmt"
EPOCH=$(/bin/date +%s | /usr/bin/numfmt --grouping)
- svnpenn 6y agoI wrote the NumFmt answer :)
- bloopernova 6y agoThank you, yet another utility that I had no idea existed! :)
- pwg 6y agoGNU coreutils printf also supports insertion of thousands separators with the ' format flag, which gives another way to add them to numbers: EPOCH=$(printf "%'d" $(date +%s))
- bloopernova 6y agoVery cool, thank you for sharing :)