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/.$//'
getsthehour
variable expansion in desired formatdate -d "$thedate" '+%dth %b %y'
getsthedate
variable expansion i.e. date desired format usingdate
Comments
Post a Comment