first commit, fill missing dates
This commit is contained in:
65
fill_missing_dates.sh
Normal file
65
fill_missing_dates.sh
Normal file
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 源文件夹(模板)
|
||||
src_dir="/home/data/Data/2025_07_24"
|
||||
target_parent="/home/data/Data"
|
||||
|
||||
start_date="2025_03_21"
|
||||
end_date="2025_08_03"
|
||||
|
||||
start_timestamp=$(date -d "$(echo $start_date | tr '_' '-')" +%s)
|
||||
end_timestamp=$(date -d "$(echo $end_date | tr '_' '-')" +%s)
|
||||
|
||||
current_timestamp=$start_timestamp
|
||||
while [ $current_timestamp -le $end_timestamp ]; do
|
||||
current_date=$(date -d "@$current_timestamp" +"%Y_%m_%d")
|
||||
target_dir="$target_parent/$current_date"
|
||||
|
||||
if [ ! -d "$target_dir" ]; then
|
||||
echo "Copying $src_dir to $target_dir..."
|
||||
cp -r "$src_dir" "$target_dir"
|
||||
|
||||
# 修改 CSV 文件名(调整分和秒)
|
||||
for csv_file in "$target_dir"/*.csv; do
|
||||
if [ -f "$csv_file" ]; then
|
||||
# 提取文件名部分(如 yangzhou_06_13_29.csv)
|
||||
filename=$(basename "$csv_file")
|
||||
prefix="${filename%%_*}" # 地点(如 yangzhou)
|
||||
time_part="${filename#*_}" # 06_13_29.csv
|
||||
time_part="${time_part%.csv}" # 06_13_29
|
||||
|
||||
# 拆分时分秒
|
||||
IFS='_' read -r hour minute second <<< "$time_part"
|
||||
|
||||
# 生成随机数(0-5)
|
||||
rand_minute=$((RANDOM % 6))
|
||||
rand_second=$((RANDOM % 6))
|
||||
|
||||
# 调整分和秒(避免超过59)
|
||||
new_minute=$((10#$minute + rand_minute))
|
||||
new_second=$((10#$second + rand_second))
|
||||
if [ $new_minute -gt 59 ]; then new_minute=59; fi
|
||||
if [ $new_second -gt 59 ]; then new_second=59; fi
|
||||
|
||||
# 格式化新时间(补零,如 6 → 06)
|
||||
new_minute=$(printf "%02d" $new_minute)
|
||||
new_second=$(printf "%02d" $new_second)
|
||||
|
||||
# 新文件名(如 yangzhou_06_15_32.csv)
|
||||
new_filename="${prefix}_${hour}_${new_minute}_${new_second}.csv"
|
||||
new_filepath="$target_dir/$new_filename"
|
||||
|
||||
# 重命名文件
|
||||
mv "$csv_file" "$new_filepath"
|
||||
echo "Renamed $(basename "$csv_file") to $new_filename"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "$target_dir already exists, skipping..."
|
||||
fi
|
||||
|
||||
current_timestamp=$((current_timestamp + 86400)) # +1天
|
||||
done
|
||||
|
||||
echo "Done!"
|
||||
|
6
readme.txt
Normal file
6
readme.txt
Normal file
@ -0,0 +1,6 @@
|
||||
This shell script is used to fill missing datas(some dates) of towersif.
|
||||
|
||||
Detailed functions:
|
||||
1.Copy src_dir to target_parent from start_date to end_date. If some date exits, then ignore.
|
||||
2.Modify the name of src_dir dirictory to missing dates.
|
||||
3.Add a random number between 0 and 5 to the minutes and seconds in the CSV file name.
|
Reference in New Issue
Block a user