#!/bin/bash

# Path to the list of names
names_file="list.txt"

# Path to the folder where you want to search for files
search_folder="'/home/litalex/share/daten/01 LITALEX Chemie/Marketing/Product/1 Austria_SDS_Litalex'"

# Destination folder to copy the files
destination_folder="'/home/litalex/share/daten/01 LITALEX Chemie/Marketing/Product/1 Austria_SDS_Litalex/2'"

# Loop through each name in the names_file
while IFS= read -r name; do
    # Search for files containing the current name
    files_found=$(grep -lR "$name" "$search_folder")

    # If files are found, copy them to the destination folder
    if [ -n "$files_found" ]; then
        echo "Files found for name: $name"
        cp -t "$destination_folder" $files_found
    else
        echo "No files found for name: $name"
    fi
done < "$names_file"
