Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要把字符串"125959"变成"12:59:59".
"125959"
"12:59:59"
显然,字符串是时间,所以正则表达式在这里不太好。
time=125959 echo ${time:0:2}:${time:2:2}:${time:4:2}
我喜欢sed:
sed
time=125959 sed -e "s/\(..\)\(..\)\(..\)/\1:\2:\3/" <<< "$time"
.
[[:digit:]]
<<<
man bash(1)