Created
July 20, 2023 06:28
-
-
Save ppdouble/fe6090e3d814db353ed0a1e224f239d3 to your computer and use it in GitHub Desktop.
Generate time sequence in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in $(seq -w 1 02); | |
do | |
for j in $(seq -w 10); | |
do | |
for k in $(seq -w 16); | |
do | |
printf '%s:%s:%s,\t' "$i" "$j" "$k"; | |
done | |
done | |
done | |
echo "" | |
echo "========================" | |
echo "" | |
for m in {1..2}; | |
do | |
for n in {0..10}; | |
do | |
for t in {0..16}; | |
do | |
printf '%02d:%02d:%02d,\t' $m $n $t; | |
done | |
done | |
done | |
echo "" | |
echo "========================" | |
echo "" | |
starttime=$(date -d "2023-07-20 01:05:33" +'%s') | |
endtime=$(date -d "2023-07-20 06:39:20" +'%s') | |
while [ "$starttime" -le "$endtime" ] | |
do | |
res=$(date -d @$starttime +'%H:%M:%S') | |
resfull=$(date -d @$starttime +'%Y-%m-%d %H:%M:%S') | |
printf "%s, %s\t" "$res" "$resfull" | |
starttime=$(($starttime+600)) | |
done | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/36394854/how-to-generate-sequential-dates-times-in-a-shell-script
https://unix.stackexchange.com/questions/60257/how-to-create-a-sequence-with-leading-zeroes-using-brace-expansion
https://unix.stackexchange.com/questions/335013/how-do-i-get-0-padded-numbers-in-brace-expansion