2

Using Linux (Redhat)

When I use dialog: --calendar to output the date. The format will be dd/mm/yyyy but I need the format to be d/m/yyyy for day and month numbers smaller than 10.

Example
Output: 01/09/2012
Result: 1/9/2012

Any suggestions are appreciated.

1
  • I tried using tr -d '0,' but it will also remove the 0 from the year as well
    – Meta
    Commented Jan 7, 2016 at 8:20

1 Answer 1

3

You can use sed. Here it removes all leading 0's appearing at the beginning of every "word": \<.

$ echo 01/09/2012 | sed 's/\<0//g'
1/9/2012

You might also used \b which match any word boundary:

$ echo 01/09/2012 | sed 's/\b0//g'
1/9/2012
3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .