#!/bin/bash
fasta_file_list="fasta_file_list.txt"
id_list="id_list.txt"
while IFS= read -r fasta_file && IFS= read -r new_id <&3; do
if [[ -f "$fasta_file" ]]; then
echo "Processing $fasta_file to rename IDs to $new_id"
temp_file=$(mktemp)
while IFS= read -r line; do
if [[ $line == \>* ]]; then
new_line=$(echo "$line" | sed -E "s/^>[^0-9]*([0-9]+.*)$/>${new_id}\1/")
echo "$new_line" >> "$temp_file"
else
echo "$line" >> "$temp_file"
fi
done < "$fasta_file"
mv "$temp_file" "$fasta_file"
else
echo "File $fasta_file does not exist"
fi
done < "$fasta_file_list" 3< "$id_list"