Shell based time and date formatting - can't add in more than a few string literals
I cobbled this together based on the man page, just skimming it though:
$date +'%m.%d.%Y'\ "%r"\ %z 05.03.2015 12:54:11 PM -0700
05.03.2015 12:54:11 PM -0700
which is as close as I can get to what I want:
05.03.2015 - 12:54:11 PM -0700
I can't seem to get the en dash in the middle. I can use a space like I have above if I escape it; looks like a % literal is done by escaping the percent with another percent e.g.: %%
There is a %n for newline, and a very few other modifiers. How do I concatenate the two delimited by a en dash?
And I would love to do this all in the date formatting like I can do in other languages. I really don't want to have to pipe to sed or awk or replace the first space with the " - ".
It's probably best to (single-) quote the entire format string as one, rather than mixing single-quotes, double-quotes and backslash escaping as you have. I certainly think that's the clearest way to write it:
date +'%m.%d.%Y - %r %z'