Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to change the date format in the contents of an XML file from 2013-01-21 to January 21

The following script works on my mac, but not on a linux server (I'll be running it as a daily cron job).


while read line; do
  case "$line" in
      echo '<date>'
      date -j -f %F `echo "$line" | sed -e 's/<date>//' -e 's-</date>--'` '+%B %d'
      echo '</date>'
      echo "$line"
done < file.xml > newfile.xml

The error I'm getting is date: illegal option -f

Is there a way to get this working on a linux server?

snippet from XML file:

    <name><![CDATA[Turnstyle Music Group Presents: bandname]]></name>
    <city><![CDATA[New York]]></city>
    <venueName><![CDATA[The National Underground]]></venueName>
    <showType><![CDATA[Bar / Pub]]></showType>

    <venueAddress><![CDATA[159 E Houston St.]]></venueAddress>
    <ticketPrice><![CDATA[$5 , $10 at the door]]></ticketPrice>

    <gmtDate>2011-10-01 00:30:00</gmtDate>
    <lastUpdate>2011-09-21 10:46:23</lastUpdate>

    <state>New York</state>
    <country>United States</country>
    <deposit>No Deposit</deposit>

share|improve this question
Can you please post some sample content of your xml file? – Guru Jan 22 '13 at 3:18
up vote 1 down vote accepted

This is happening because the OS X implementation of the date command is taken from the BSD family. Since you're only feeding in one line at a time, it should be safe to use the -d parameter instead:

date -d `echo "$line" | sed -e 's/<date>//' -e 's-</date>--'` '+%B %d'

This is assuming that your input format remains compatible between the two date implementations. If it's not, you'll need to get it in a different format first.

share|improve this answer
looks like that did the trick — thanks! – Ben L. Jan 22 '13 at 4:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.