![]() |
Trouble with sed. (Updated)
Code:
echo Todays date is $(date +%A\,\ %B\ %d\,\ %Y).Code:
Todays date is Tuesday, September 08, 1995.Code:
Todays date is Tuesday, September 8, 1995.Code:
i.e. September 30, 1995.Code:
September 08, 2000.Code:
echo It is currently $(date +%I\:%M\ %p).Code:
It is currently 08:58 AM.Code:
It is currently 08:50 AM.Code:
It is currently 8:50 AM. |
Solved first question.
Quote:
Still need help on the second question. Edit: Shortened first post. |
For problem #2, I believe the answer is in the man page for `date` - look at the formatting modifiers further down the page. A snippet:
Code:
By default, date pads numeric fields with zeroes. The following optional flags may follow `%': |
Quote:
http://developer.apple.com/library/m...n1/date.1.html I can't wait to get a new computer. For now however, I have to deal with it. :( Code:
Andrew@MacBook-Pro:~$ echo "Today\'s date is $(date +%A\,\ %B\ %d\,\ %Y). It is currently $(date %-I\:%M\ %p)." |
You have tried hard and qudos for that! :)
First problem solution: alias tyme="echo Today$'\''s date is \$(date +%A\,\ %B\ %d\,\ %Y). It is currently \$(date +%I\:%M\ %p).". The $'\'' is ANSI-C Quoting. Second problem solution: use %-d and %-M instead of %d and %M. From the date man page: "By default, date pads numeric fields with zeroes. The following optional flags may follow `%': - (hyphen) do not pad the field". Your first problem solution does not work because it sets the time when the alias is defined (as alias tyme would show) but a slightly modified form dos work: alias tyme="echo Today\'s date is \$(date +%A\,\ %B\ %d\,\ %Y). It is currently \$(date +%I\:%M\ %p)." EDIT: your solution is neater than the ANSI-C Quoting solution -- would have sworn I'd tried it! |
Indeed, that's pesky! :)
Not thoroughly tested, but maybe: Code:
sed 's/ [0]*/ /g'Good luck! (Sorry if you already tried this one - I did not examine ALL of your attempts intensely). |
By the way, you can save some backslashes, commas don't need escapes quotes can be used instead of escaping the spaces:
Code:
alias tyme="echo Today\'s date is $(date '+%A, %B %e, %Y'). It is currently $(date '+%l:%M %p')."Code:
%d is replaced by the day of the month as a decimal number (01-31). |
Quote:
Thanks though... Very informative. |
Quote:
|
Quote:
I swear I tried it too... Somehow it snuck past me. :scratch: Though, since that is ANSI-C, isn't that more 'correct' since it's standards compliant? |
Well, not exactly the neatest way to say this -- 4 posts in a row. :eek:
Anyway, I gave everyone here reputation and a very customized thank you! Within an hour and a half I had all kinds of good answers! Don't know how to say thanks anymore so I'll say it once more: Thanks again to GrapefruiTgirl, catkin and ntubski! :hattip: |
Quote:
Everyone who has some idea what they're talking about today, began at nothing in the beginning. You're further back on the scripting than some of us, and also you're further ahead than some of us; but there's ALWAYS something more to learn, no matter how much one knows.. Cheers! |
Just to follow up on the thread, I ended up using this string:-
Code:
alias tyme="echo Today\'s date is $(date +%A\,\ %B\ %d\,\ %Y | sed 's/ [0]*/ /g'). It is currently $(date +%I\:%M\ %p | sed 's/ [0]*/ /g')."Hope this helps anyone passing along (though I doubt anyone will come across this situation). Thanks again. :hattip: |
| All times are GMT -5. The time now is 09:14 AM. |