i need to convert the text below in bash script
111319 2036
to
11/13/19 20:36
it's possible?
regards.
i need to convert the text below in bash script
111319 2036
to
11/13/19 20:36
it's possible?
regards.
With GNU awk:
awk -v FIELDWIDTHS='2 2 2 1 2 2' '{ print $1 "/" $2 "/" $3 " " $5 ":" $6 }'
The traditional solution would be to do something with sed
sed 's!^\(..\)\(..\)\(..\) \(..\)\(..\)!\1/\2\/\3 \4:\5!'
For example:
% echo 111319 2036 | sed 's!^\(..\)\(..\)\(..\) \(..\)\(..\)!\1/\2\/\3 \4:\5!'
11/13/19 20:36
There's also the possibility of a pure bash
solution.
If, for example, you have the value in $a then
${a:0:2}/${a:2:2}/${a:4:2} ${a:7:2}:${a:8:2}
For example:
$ a="111319 2036"
$ echo ${a:0:2}/${a:2:2}/${a:4:2} ${a:7:2}:${a:8:2}
11/13/19 20:03
echo "111319 2036"| awk '{print substr($1,1,2)"/"substr($1,3,2)"/"substr($1,5,2) " " substr($NF,1,2)":"substr($NF,3,4)}'
output
11/13/19 20:36