0

I'm trying to use the date bash command to get a string like this:

(May 30th, 2022)

I'm getting close with date +"(%B %-d, %Y)", which prints string like that:

(May 30, 2022)

However, the th suffix is missing.

Which format string should I use with date to get the st, nd or th suffix, please?

Thanks in advance!

fgalan
  • 10,933
  • 8
  • 40
  • 81

1 Answers1

1

Try

date +"(%B %-d, %Y)" | sed 's/1,/1st,/;s/2,/2nd,/;s/3,/3rd,/;s/\([0-9]\),/\1th,/'
  • You can easily combine these `sed` scripts into one; see https://stackoverflow.com/questions/7657647/combining-two-sed-commands – tripleee May 30 '22 at 10:10