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)