1

I have some date other than current date in unix and I want to convert into a specific format

Original Format
D="Mon Dec 30 06:35:02 EST 2013"

New Format
E=20131230063502
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Prabhat
  • 45
  • 2
  • 6

2 Answers2

1

E=`date +%Y%m%d%H%M%S`

this is the way to format the output of the date command and save it in the variable E

Romme
  • 26
  • 1
0

Using python:

def data(dstr):
    m = {'Jan': '01', 'Feb':'02', 'Mar':'03', 'Apr':'04', 'May':'05', 'Jun':'06', 'Jul':'07', 'Aug':'08', 'Sep':'09', 'Oct':'10', 'Nov':'11', 'Dec':'12'}
    val = dstr.split(' ')
    month = m[val[1]]
    time = val[3].split(':')
    return '{}{}{}{}{}{}'.format(val[-1],month,val[2],time[0],time[1],time[2])

if __name__ == '__main__':
    print data("Mon Dec 30 06:35:02 EST 2013")

In: Mon Dec 30 06:35:02 EST 2013

Out: 20131230063502

Randomazer
  • 172
  • 5