Copying files from multiple directories into a single destination directory

前端 未结 4 2015
挽巷
挽巷 2021-01-24 09:14

There are multiple directories which contain a file with the same name:

direct_afaap/file.txt
direct_fgrdw/file.txt
direct_sardf/file.txt
...

N

4条回答
  •  逝去的感伤
    2021-01-24 09:47

    while read -r line; do 
       suffix=$(sed 's/^.*_\(.*\)\/.*$/\1/' <<<$line)
       newfile=$(sed 's/\.txt/$suffix\.txt/' <<<$line)
       cp "$line" "~/direct_new/$newfile"
    done 

    where file_list is a list of your files.

提交回复
热议问题