ops/research/ad_hoc/rearrange2.sh
2025-01-13 20:04:52 -05:00

34 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# by chatGPT
# ==========================================
# hs01.cvtt.vpn SETTINGS
# ==========================================
# Define source and destination base directories
SOURCE_BASE_DIR="/works/cvtt/md_archive/equity/alpaca_md.OLD" # Replace with your actual source directory
DESTINATION_BASE_DIR="/works/cvtt/md_archive/equity/alpaca_md" # Replace with your destination directory
# Loop through all .db.gz files in the source directory
find "$SOURCE_BASE_DIR" -type f -name "*.db.gz" | while read -r file; do
# Extract relevant directory components from the path
relative_path="${file#$SOURCE_BASE_DIR/}"
ticker=$(echo "$relative_path" | cut -d'/' -f2)
year=$(echo "$relative_path" | cut -d'/' -f3)
original_date=$(basename "$file" | cut -d'.' -f1)
# Define the new file name and destination path
new_file_name="${original_date}.${ticker}.alpaca_1m_bars.db.gz"
destination_dir="$DESTINATION_BASE_DIR/$year/A/$ticker"
# Create the destination directory if it doesn't exist
mkdir -p "$destination_dir"
#echo DEBUG mkdir -p "$destination_dir"
# Move and rename the file
mv "$file" "$destination_dir/$new_file_name"
#echo DEBUG mv "$file" "$destination_dir/$new_file_name"
echo "Moved $file to $destination_dir/$new_file_name"
done