print date from string as date in bash -


what bashonic way of converting following text:

specifications of bla/bla.txt created @ 181438 on 20160720 

into:

specifications of bla/bla.txt created @ 18:14:38 on 20th july 2016 

i'm generating message with:

printf "specifications of %s created @ %d on %d\n" "$1" "$thehour" "$thedate" 

and $thehour , $thedate extracted bla.txt. not related file tags or actual creation date of file.

i'm asking if bash offers such functionality, , if not, how can 1 achieve easily.

with gnu date:

$ thehour=181438 $ thedate=20160720 $ printf 'specifications of bla/bla.txt created @ %s on %s\n' "$(sed \    's/../&:/g' <<<"$thehour"|sed 's/.$//')" "$(date -d "$thedate" '+%dth %b %y')" 

output:

specifications of bla/bla.txt created @ 18:14:38 on 20th july 2016 

  • sed 's/../&:/g' <<<"$thehour"|sed 's/.$//' gets thehour variable expansion in desired format

  • date -d "$thedate" '+%dth %b %y' gets thedate variable expansion i.e. date desired format using date


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -