0

I have a list of filenames without file extensions. I want to loop that list and search for every file-prefix and if a file was found then copy it to a location.

Right now my script produces *2209589 from string 32201069. But instead 32201069 should become 32201069* to the -name parameter of find!

My problem is, I cant append an * asterisk to my names from the file, as "{$filename}* seems to override the first character of the filename string instead of appending it.

while read filename; do
    find . -name "${filename}*" -print \
         -exec cp -n {} /Users/herrsch/Desktop/foundimages \;;
done < /Users/herrsch/Desktop/fileprefixes.txt
geekhunger
  • 470
  • 5
  • 9
  • Your code looks fine. I can't think of any way that it would change `32201069` to `2209589`. – Barmar Jan 13 '20 at 07:02
  • I don't think this is reproducible. What exactly is in `fileprefixes.txt`? – tripleee Jan 13 '20 at 07:05
  • What do you mean by "override the first character of the filename"? How does that relate to the transformation you describe? They're completely different, not just the first character. – Barmar Jan 13 '20 at 07:09
  • @tripleee my filenames, that i search for always start with 8 digit prefix. These prefixes are inside that file. Each line for each one file prefix.. ```32208444\n32201069\n32202955\n...``` – geekhunger Jan 13 '20 at 07:12
  • 1
    The best hypothesis I can come up with is that the input file is malformed somehow. Can you [edit] the question to include a snippet, perhaps with a hex dump of the first line or two to show that there are no invisible control characters there? – tripleee Jan 13 '20 at 07:21
  • @tripleee YES! You have been right! It was formated in UTF-8 and CRLF linebreaks "\r\n" - I converted it to LF "\n" and ISO-8859-1 aaand it worked! Thank you so much! I have been days at it.. – geekhunger Jan 13 '20 at 07:28
  • 1
    Probably keep it in UTF-8 though. – tripleee Jan 13 '20 at 07:29

0 Answers0