문제

I'm tring to move a collection of files from one directory to another.

I have a .txt list with PARTIAL name of the files (one per line) I want to move.

Example:

-> file name: "00012377000160-52200308419 -20100101-20101231-G-E92F9BA0A0C932C331273FCD845719813F0B617-1-GTOGR-FDS.txt"

-> what I have from the filename in my .txt file: E92F9BA0A0C932C331273FCD845719813F0B617

It seems simple, I have to: 1- find the files witch names CONTAIN the strings that are stored in my .txt file 2- then move them to the directory

But..... I'm doing something wrong (maybe expansion order ?)....

This is how I'm trying:

for PARTNAME in `cat LIST.TXT`; do mv *"$PARTNAME"* /NEWDIR ; done

The wildcards * (anyting after or before the PARTIAL file name) is not working.... it´s been considered as part of the file name, instaed

Any help will be apreciated !!!

도움이 되었습니까?

해결책

Simply:

while read -r PART; do
    mv *"$PART"*.txt /NEWDIR
done < list.txt

Also although I don't recommend word splitting, the way to make your code work was just to properly place your $ sign along with the parameter:

for PARTNAME in `cat LIST.TXT`; do mv *"$PARTNAME"* /NEWDIR ; done
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top