#!/bin/bash

# Directory where the original files are
original_dir="/nird/projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/S800"
# Directory where you want the new file
new_dir="/nird/projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/shared/oyvfoss/S800/S800_v1_renamed"

# Loop through each .nc4 file in the original directory
for file in "$original_dir"/*avg*.nc4_*; do  # Extract the base filename without the timestamp (everything after the last underscore)

  base_name=$(basename "$file" | sed 's/_([0-9][0-9]*)$//')  # Remove timestamp part
  
  # Remove any period (.) from the base name
  base_name_no_period=$(echo "$base_name" | tr -d '.')

  # Create the new filename, replacing `.nc4` with `.nc`
  new_name="${base_name_no_period}.nc"

  # Create the symlink in the target directory
  cp "$file" "$symlink_dir/$new_name"
done
